Do you really need compile time? There is a temporary conversion between the two, so I don't see the need for this:
vector2<int, char> a(13, 'b'); vector<int, char> b = a;
I tried, however, to play. I am not happy with my answer, but maybe you can work on it to find something better.
I was hoping that I could use some meta-function, but it seems to me inaccessible. In addition, with this approach, you need to define it as many times as you have different values.
Perhaps the best solution would be to first convert to a tuple ...
#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'); }
source share