実際にコンパイル時のキャストが必要ですか? 両方の間に実行時の変換があるため、実際には必要性がわかりません:
vector2<int, char> a(13, 'b');
vector<int, char> b = a;
しかし、私は遊んでみました。私は私の答えに満足していませんが、もっと良いものを見つけるためにそれに取り組むことができるかもしれません.
何らかのメタ機能を使用できることを望んでいましたが、それは私の能力を超えているようです。さらに、このアプローチでは、異なる値を持つ回数だけ定義する必要があります。
おそらく、最初にタプルに変換する方が良い解決策になるでしょう…</p>
#include <boost/fusion/container/vector.hpp>
#include <boost/fusion/container/vector/vector10.hpp>
#include <boost/fusion/include/at.hpp>
#include <boost/type_traits/remove_reference.hpp>
using namespace boost::fusion;
template<typename NumVec2>
struct cast {
typedef typename result_of::at_c<NumVec2, 0>::type T1;
typedef typename result_of::at_c<NumVec2, 1>::type T2;
typedef vector<typename boost::remove_reference<T1>::type, typename boost::remove_reference<T2>::type > type;
};
int main(int, char**){
vector2<int, char> a(13, 'b');
typedef cast< vector2<int,char> >::type casted_t;
casted_t other(10, 'f');
}