Re: How to implement std::tuple's sometimes std::pair constructor?
Am 02.08.2013 22:47, schrieb Daniel Kr?gler:
If you only want to impose constraint upon the size, this can be solved
like this:
template <class U1, class U2,
typename std::enable_if<std::tuple_size<my_tuple>::value == 2,
bool>::type = false
>
my_tuple(const std::pair<U1, U2>&);
Oops, the heat has burned my brain: The suggested approach doesn't work
as promised, because I inverted the roles of type-dependency here. We
need to ensure that the member template uses type-dependent expressions
within the sfinae-test, but this doesn't happen here: Given an
instantiation of my_tuple<Types...> the expression
std::tuple_size<my_tuple>::value is not dependent on U1 and U2 (that is
needed here), so lets fix that by using my previously suggested
pack_size template as follows:
template<class U1, class U2,
typename std::enable_if<sizeof...(Types) == pack_size<U1, U2>(),
bool>::type = false
>
my_tuple(const std::pair<U1, U2>&);
You can use std::tuple_size<my_tuple>::value instead of
sizeof...(Types), but it is not necessary.
My last example of my previous reply regarding implied size-checks
should be correct, though, because the test-expression contains the
type-dependency of the member-template.
I apologize for my initial misleading response.
HTH & Greetings from Bremen,
- Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]