Hi,
While working on improving of implementation of data driven tests, I found
rather annoying bug in MSVC-12.0 with variadic templates. The code seems
to work fine with msvc-14.0, gcc 4.8 and clang 3.4. I did not try msvc-
13.0. Does anyone know a workaround? Example follows (try to comment
on/off line: auto const& t3).
Gennadiy
// C++ 14 index_sequence
template
struct index_sequence {};
template
struct merge_index_sequence;
template
struct merge_index_sequence,
index_sequence> {
typedef index_sequence type;
};
template
struct make_index_sequence {
typedef typename merge_index_sequence<
typename make_index_sequence::type,
typename make_index_sequence<(B + E)/2, E>::type>::type type;
};
template
struct make_index_sequence::type> {
typedef index_sequence<B> type;
};
template
using index_sequence_for =
typename make_index_sequence<0, sizeof...(T)>::type;
//////////////////////////////////////////////////////////////////////////
template
struct merged_tuple {
typedef std::tuple type;
typedef std::tuple ref;
};
template
struct merged_tuple> {
typedef std::tuple type;
typedef std::tuple ref;
};
template
struct merged_tuple, T1> {
typedef std::tuple type;
typedef std::tuple ref;
};
template
struct merged_tuple, std::tuple> {
typedef std::tuple type;
typedef std::tuple ref;
};
template
inline typename merged_tuple, std::tuple>::ref
tuple_merge_impl( std::tuple const& a1,
std::tuple const& a2,
index_sequence const& ,
index_sequence const& )
{
using ref_type = typename merged_tuple,
std::tuple>::ref;
return ref_type( std::get<I1>(a1)..., std::get<I2>(a2)... );
}
template
inline typename merged_tuple, std::tuple>::ref
tuple_merge_impl( std::tuple const& a1,
std::tuple const& a2 )
{
return tuple_merge_impl( a1, a2,
index_sequence_for{},
index_sequence_for{} );
}
template<typename T>
inline std::tuple
as_tuple( T const& arg )
{
return std::tuple( arg );
}
template
inline std::tuple const&
as_tuple( std::tuple const& arg )
{
return arg;
}
template
inline typename merged_tuple::ref
tuple_merge( T1 const& a1, T2 const& a2 )
{
return tuple_merge_impl( as_tuple( a1 ), as_tuple( a2 ) );
}
int main()
{
auto const& t1 = tuple_merge( 1, 2 );
auto const& t2 = tuple_merge( 3, 4 );
auto const& t3 = tuple_merge( t1, 5 );
auto const& t4 = tuple_merge( 6, t2 );
return 0;
}