fork download
  1. #include<type_traits>
  2. #include<array>
  3.  
  4. namespace detail {enum class enabler {};}
  5. using SInd = unsigned;
  6. using Num = double;
  7. template<SInd nd> using NumA = std::array<Num,nd>;
  8.  
  9. template<class C, class T = int>
  10. using EnableIf = typename std::enable_if<C::value, T>::type;
  11.  
  12. template<class T, T a, T b> struct equal : std::integral_constant<bool, a == b> {};
  13.  
  14. struct x {};
  15.  
  16. template<SInd nd, EnableIf<equal<SInd,nd,2>>... >
  17. NumA<nd> vector(x,Num d,Num off){ return NumA<nd>{d,off}; }
  18. template<SInd nd, EnableIf<equal<SInd,nd,3>>... >
  19. NumA<nd> vector(x,Num d,Num off){ return NumA<nd>{d,off,off}; }
  20.  
  21. template<SInd nd, class edg> NumA<nd> center(edg) {
  22. static_assert(nd == 3, "ok1");
  23. static_assert(nd == 3 && equal<SInd,nd,3u>::value, "ok2");
  24. static_assert(!equal<SInd,nd,2u>::value, "ok3");
  25. static_assert( (nd == 2 && equal<SInd,nd,2u>::value)
  26. || (nd == 3 && equal<SInd,nd,3u>::value),
  27. "something went wrong");
  28.  
  29. return vector<nd>(edg(),1.0,1.0);
  30. }
  31.  
  32.  
  33. int main() {
  34.  
  35. static const SInd nd = 3;
  36.  
  37. center<nd>(x());
  38. }
Success #stdin #stdout 0s 2892KB
stdin
Standard input is empty
stdout
Standard output is empty