std::is_tr1_tuple<T> - how?

Hi! While migrating from boost::tuple to std::tr1::tuple (pain!) I have to rewrite a lot of compile-time-magic code. Among other things I am in need of a type info template <typename T> struct is_tr1_tuple; Any implementation hint or proposal welcome. best regards, Markus

Markus Werle wrote:
While migrating from boost::tuple to std::tr1::tuple (pain!) I have to rewrite a lot of compile-time-magic code. Among other things I am in need of a type info
template <typename T> struct is_tr1_tuple;
Any implementation hint or proposal welcome.
This is tricky, when BOOST_HAS_TR1_TUPLE is *not* defined, then std::tr1::tuple is an alias for either boost::fusion::tuple or boost::tuple (the latter for broken Borland compilers only), so your existing metacode should work. When BOOST_HAS_TR1_TUPLE *is* defined then std::tr1::tuple is the std lib's native implementation, you could probably use function overload resolution to detect that: template <class T1, class T2 ... class T10> char is_tr1_tuple_test(const std::tr1::tuple<T1....T10>&); template <class T> double is_tr1_tuple_test(const T&); template <class T> struct is_tr1_tuple { static const T m_t; static const bool value = sizeof(is_tr1_tuple_test(m_t) == 1; }; In fact I think that should work for the case that BOOST_HAS_TR1_TUPLE is not defined as well? HTH, John.

Markus Werle wrote:
John Maddock <john <at> johnmaddock.co.uk> writes:
template <class T1, class T2 ... class T10> char is_tr1_tuple_test(const std::tr1::tuple<T1....T10>&);
Unfortunately the syntax "T1....T10" as template argument seems not to be implemneted for vc8 ...
Sorry, that was shorthand for writing out in full template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, classT9, class T10> I just didn't want to have to type all that out :-( HTH, John.

John Maddock <john <at> johnmaddock.co.uk> writes:
Markus Werle wrote:
John Maddock <john <at> johnmaddock.co.uk> writes:
template <class T1, class T2 ... class T10> char is_tr1_tuple_test(const std::tr1::tuple<T1....T10>&);
Unfortunately the syntax "T1....T10" as template argument seems not to be implemneted for vc8 ...
Sorry, that was shorthand for writing out in full
template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, classT9, class T10>
But this code then only works if and only if the maximum number of arguments is exactly 10, right? Markus

Markus Werle:
template <class T1, class T2 ... class T10> char is_tr1_tuple_test(const std::tr1::tuple<T1....T10>&);
...
But this code then only works if and only if the maximum number of arguments is exactly 10, right?
It should work for tuples with up to ten parameters, even if the maximum is higher. (I think that the straightforward partial specialization approach should, too.)

Markus Werle wrote:
But this code then only works if and only if the maximum number of arguments is exactly 10, right?
I hope not :-( Because it's a function overload (rather than a template partial specialisation) it should work as long as the max number of args is 10 or more. HTH, John.
participants (3)
-
John Maddock
-
Markus Werle
-
Peter Dimov