| open-mgl-dev (開発バージョン) (0.7.9.80) | 2009-11-02 22:25 |
| open-mgl (DirectX9, VC++2008) (0.7.9) | 2009-09-27 20:32 |
| roast-dev (開発バージョン) (0.0.1.40-dev) | 2009-11-02 23:09 |
>FrontPage>Roast+>リファレンス>std>container_convert.hpp>container_convert
コンテナ配列から、異なる型のコンテナ配列へと変換を行います。
roast/std/container_convert.hpp :
container_convert() 関数は、コンテナ配列 from から、異なるコンテナ配列 to へのコピーを行います。
from と to は同じコンテナ配列型である必要はありません。コンテナ配列型としては std::vector, std::list 等が使えますが、stdコンテナ配列以外の型を使用する事も出来ます。
ただしこの場合、以下の条件を満たしている必要があります。
from と to の要素の型は異なっていても構いません。ただしこの場合、to の要素型は、from の要素型からの変換をサポートしている必要があります。
(to の要素型がクラスである場合、from の要素型を引数とするコンストラクタを実装している必要があります)
以下に示すサンプルコードでは、from と to のコンテナ型も、要素の型も異なっている場合を例に取り上げます。
- class CHoge1{
- public:
- int m_a;
- CHoge1(int x){ m_a = x; }
- };
- class CHoge2{
- public:
- int m_b;
- CHoge2(const CHoge1 &from){
- m_b = from.m_a;
- }
- };
- void main()
- {
- std::list<CHoge1> hoge1Ary;
- std::vector<CHoge2> hoge2Ary;
- hoge1Ary.push_back(CHoge1(10));
- hoge1Ary.push_back(CHoge1(20));
- container_convert(hoge1Ary, hoge2Ary);
- printf("%d\n", hoge2Ary[0].m_b );
- printf("%d\n", hoge2Ary[1].m_b );
- }
初期版数からサポート。