fork(1) download
  1. #include <type_traits>
  2. #include <array>
  3.  
  4. template<typename... TArgs> struct
  5. contains_only_array_of_3_int
  6. {
  7. static constexpr bool const value{false};
  8. };
  9.  
  10. template<typename TBack> struct
  11. contains_only_array_of_3_int<TBack>
  12. {
  13. static constexpr bool const value
  14. {
  15. ::std::is_same<::std::array<int, 3>, TBack>::value
  16. };
  17. };
  18.  
  19. template<typename TFront, typename... TRest> struct
  20. contains_only_array_of_3_int<TFront, TRest...>
  21. {
  22. static constexpr bool const value
  23. {
  24. contains_only_array_of_3_int<TFront>::value
  25. &&
  26. contains_only_array_of_3_int<TRest...>::value
  27. };
  28. };
  29.  
  30. template<std::size_t V> class
  31. Test
  32. {
  33. public:
  34. Test() {}
  35.  
  36. template <typename... TArgs>
  37. Test(TArgs && ... args)
  38. {
  39. static_assert(sizeof...(TArgs) == V, "arguments count mismatch");
  40. static_assert(contains_only_array_of_3_int<TArgs...>::value, "arguments type mismatch");
  41. }
  42. };
  43.  
  44. int main()
  45. {
  46. Test<1> t
  47. {
  48. ::std::array<int, 3>{ 1, 2, 3 }
  49. };
  50. Test<2> t2
  51. {
  52. ::std::array<int, 3>{ 1, 2, 3 }
  53. , ::std::array<int, 3>{ 4, 5, 6 }
  54. };
  55. Test<3> t3
  56. {
  57. ::std::array<int, 3>{ 1, 2, 3 }
  58. , ::std::array<int, 3>{ 4, 5, 6 }
  59. , ::std::array<int, 3>{ 7, 8, 9 }
  60. };
  61. Test<3> t3_args_count_fail
  62. {
  63. ::std::array<int, 3>{ 1, 2, 3 }
  64. , ::std::array<int, 3>{ 4, 5, 6 }
  65. };
  66. Test<3> t3_args_tupe_fail
  67. {
  68. ::std::array<int, 3>{ 1, 2, 3 }
  69. , ::std::array<int, 2>{ 4, 5 }
  70. , ::std::array<int, 3>{ 7, 8, 9 }
  71. };
  72. return(0);
  73. }
Compilation error #stdin compilation error #stdout 0s 15240KB
stdin
Standard input is empty
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
Standard output is empty