fork download
  1. #include <array>
  2.  
  3. struct point_tag {};
  4. struct triangle_tag {};
  5.  
  6. template<typename Geometry = void, typename Enable = void>
  7. struct tag
  8. {
  9. typedef void type;
  10. };
  11.  
  12. template <typename Point>
  13. struct tag<std::array<Point, 3>,
  14. typename std::enable_if <std::is_base_of<typename tag<Point>::type, point_tag>::value>::type>
  15. {
  16. typedef triangle_tag type;
  17. };
  18.  
  19. template<typename Point>
  20. using triangle =
  21. typename std::enable_if
  22. <
  23. std::is_base_of<typename tag<Point>::type, point_tag>::value,
  24. std::array<Point,3>
  25. >::type;
  26.  
  27. class Point{};
  28.  
  29. template<>
  30. struct tag<Point>
  31. {
  32. typedef point_tag type;
  33. };
  34.  
  35. static_assert(std::is_same<triangle_tag, tag<std::array<Point, 3>>::type>::value, "");
  36. static_assert(std::is_same<void, tag<std::array<int, 3>>::type>::value, "");
  37. static_assert(std::is_same<triangle_tag, tag<triangle<Point>>::type>::value, "");
  38. //static_assert(std::is_same<triangle_tag, tag<triangle<int>>::type>::value, ""); // Doesn't compile as triangle<int> is not valid
  39.  
  40. int main()
  41. {
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 3336KB
stdin
Standard input is empty
stdout
Standard output is empty