#include <type_traits>
#include <array>
template < typename ... TArgs > struct
contains_only_array_of_3_int
{
static constexpr bool const value{ false } ;
} ;
template < typename TBack> struct
contains_only_array_of_3_int< TBack>
{
static constexpr bool const value
{
:: std :: is_same < :: std :: array < int , 3 > , TBack> :: value
} ;
} ;
template < typename TFront, typename ... TRest > struct
contains_only_array_of_3_int< TFront, TRest...>
{
static constexpr bool const value
{
contains_only_array_of_3_int< TFront> :: value
&&
contains_only_array_of_3_int< TRest...> :: value
} ;
} ;
template < std:: size_t V> class
Test
{
public :
Test( ) { }
template < typename ... TArgs >
Test( TArgs && ... args )
{
static_assert( sizeof ...( TArgs) == V, "arguments count mismatch" ) ;
static_assert( contains_only_array_of_3_int< TArgs...> :: value , "arguments type mismatch" ) ;
}
} ;
int main( )
{
Test< 1 > t
{
:: std :: array < int , 3 > { 1 , 2 , 3 }
} ;
Test< 2 > t2
{
:: std :: array < int , 3 > { 1 , 2 , 3 }
, :: std :: array < int , 3 > { 4 , 5 , 6 }
} ;
Test< 3 > t3
{
:: std :: array < int , 3 > { 1 , 2 , 3 }
, :: std :: array < int , 3 > { 4 , 5 , 6 }
, :: std :: array < int , 3 > { 7 , 8 , 9 }
} ;
Test< 3 > t3_args_count_fail
{
:: std :: array < int , 3 > { 1 , 2 , 3 }
, :: std :: array < int , 3 > { 4 , 5 , 6 }
} ;
Test< 3 > t3_args_tupe_fail
{
:: std :: array < int , 3 > { 1 , 2 , 3 }
, :: std :: array < int , 2 > { 4 , 5 }
, :: std :: array < int , 3 > { 7 , 8 , 9 }
} ;
return ( 0 ) ;
}
I2luY2x1ZGUgPHR5cGVfdHJhaXRzPgojaW5jbHVkZSA8YXJyYXk+Cgp0ZW1wbGF0ZTx0eXBlbmFtZS4uLiBUQXJncz4gc3RydWN0CmNvbnRhaW5zX29ubHlfYXJyYXlfb2ZfM19pbnQKewoJc3RhdGljIGNvbnN0ZXhwciBib29sIGNvbnN0IHZhbHVle2ZhbHNlfTsKfTsKCnRlbXBsYXRlPHR5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Q6OmFycmF5PGludCwgMz57IDQsIDUsIDYgfQoJfTsKCVRlc3Q8Mz4gdDMKCXsKCQk6OnN0ZDo6YXJyYXk8aW50LCAzPnsgMSwgMiwgMyB9CgksCTo6c3RkOjphcnJheTxpbnQsIDM+eyA0LCA1LCA2IH0KCSwJOjpzdGQ6OmFycmF5PGludCwgMz57IDcsIDgsIDkgfQoJfTsKCVRlc3Q8Mz4gdDNfYXJnc19jb3VudF9mYWlsCgl7CgkJOjpzdGQ6OmFycmF5PGludCwgMz57IDEsIDIsIDMgfQoJLAk6OnN0ZDo6YXJyYXk8aW50LCAzPnsgNCwgNSwgNiB9Cgl9OwoJVGVzdDwzPiB0M19hcmdzX3R1cGVfZmFpbAoJewoJCTo6c3RkOjphcnJheTxpbnQsIDM+eyAxLCAyLCAzIH0KCSwJOjpzdGQ6OmFycmF5PGludCwgMj57IDQsIDUgfQoJLAk6OnN0ZDo6YXJyYXk8aW50LCAzPnsgNywgOCwgOSB9Cgl9OwoJcmV0dXJuKDApOwp9
compilation info
prog.cpp: In instantiation of ‘Test<V>::Test(TArgs&& ...) [with TArgs = {std::array<int, 3ul>, std::array<int, 3ul>}; long unsigned int V = 3ul]’:
prog.cpp:65:2: required from here
prog.cpp:39:3: error: static assertion failed: arguments count mismatch
static_assert(sizeof...(TArgs) == V, "arguments count mismatch");
^~~~~~~~~~~~~
prog.cpp: In instantiation of ‘Test<V>::Test(TArgs&& ...) [with TArgs = {std::array<int, 3ul>, std::array<int, 2ul>, std::array<int, 3ul>}; long unsigned int V = 3ul]’:
prog.cpp:71:2: required from here
prog.cpp:40:3: error: static assertion failed: arguments type mismatch
static_assert(contains_only_array_of_3_int<TArgs...>::value, "arguments type mismatch");
^~~~~~~~~~~~~
stdout