fork download
  1. #include <array>
  2.  
  3. // to_array implementation taken from http://e...content-available-to-author-only...e.com/w/cpp/experimental/to_array
  4. namespace detail {
  5. template <class T, std::size_t N, std::size_t... I>
  6. constexpr std::array<std::remove_cv_t<T>, N>
  7. to_array_impl(T (&a)[N], std::index_sequence<I...>)
  8. {
  9. return { {a[I]...} };
  10. }
  11. }
  12.  
  13. template <class T, std::size_t N>
  14. constexpr std::array<std::remove_cv_t<T>, N> to_array(T (&a)[N])
  15. {
  16. return detail::to_array_impl(a, std::make_index_sequence<N>{});
  17. }
  18. // End of to_array implementation
  19.  
  20. struct blah { };
  21.  
  22. template<std::size_t N>
  23. constexpr auto foo(const blah(&arr)[N])
  24. {
  25. return to_array(arr);
  26. }
  27.  
  28. int main()
  29. {
  30. auto res = foo({{}, {}});
  31. return 0;
  32. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Standard output is empty