fork download
  1. #include <array>
  2.  
  3. // Assume this comes from some included file
  4. constexpr size_t elementCount = 5;
  5.  
  6. template<class first, class ... T>
  7. std::array<first, 1 + sizeof...(T)> makeArray(first e1, T ... rest) {
  8. static_assert(1 + sizeof...(T) == elementCount, "Must match elementCount");
  9. return { std::forward<first>(e1), std::forward<T>(rest) ...};
  10. }
  11.  
  12. int main() {
  13. // This works.
  14. const auto lookup = makeArray(2, 4, 6, 8, 10);
  15.  
  16. // This doesn't. :-)
  17. //const auto lookup2 = makeArray(2, 4, 6);
  18. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
Standard output is empty