fork download
  1. #include <iostream>
  2.  
  3. template<typename = void>
  4. struct A_impl
  5. {
  6. static A_impl const values[];
  7. static A_impl const& X;
  8. static A_impl const& Y;
  9. static A_impl const& Z;
  10.  
  11. constexpr operator int() const { return _value; }
  12.  
  13. int const _value;
  14. };
  15.  
  16. template<typename T>
  17. constexpr A_impl<T> const A_impl<T>::values[]{ 42, 43, 44 };
  18. template<typename T>
  19. constexpr A_impl<T> const& A_impl<T>::X{ values[0U] };
  20. template<typename T>
  21. constexpr A_impl<T> const& A_impl<T>::Y{ values[1U] };
  22. template<typename T>
  23. constexpr A_impl<T> const& A_impl<T>::Z{ values[2U] };
  24.  
  25. using A = A_impl<>;
  26.  
  27. template<int N>
  28. constexpr int foo()
  29. {
  30. return N;
  31. }
  32.  
  33. int main(int, char**) noexcept
  34. {
  35. std::cout << foo<A::values[1U]>() << "\n"
  36. << foo<A::Z>();
  37. return 0;
  38. }
Success #stdin #stdout 0s 4536KB
stdin
Standard input is empty
stdout
43
44