Advertisement
JoshDreamland

Template test cases

Jul 8th, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1.  
  2. template<int x> struct factorial {
  3.   enum r {
  4.     value = x * factorial<x - 1>::value
  5.   };
  6. };
  7.  
  8. template<> struct factorial<1> {
  9.   enum r {
  10.     value = 1
  11.   };
  12. };
  13.  
  14. class seventwenty: factorial<6> {
  15. };
  16.  
  17. template<bool e, class t, class f> class ternary {
  18.   typedef void tp;
  19. };
  20.  
  21. template<class t, class f> class ternary<true, t, f> {
  22.   typedef t tp;
  23. };
  24.  
  25. template<class t, class f> class ternary<false, t, f> {
  26.   typedef f tp;
  27. };
  28.  
  29.  
  30. template<typename o, typename p, typename q> struct matches {
  31.   enum { value = 1 };
  32. };
  33.  
  34. template<typename qq, typename pp> struct matches<pp, qq, qq> {
  35.   enum { value = 2 };
  36. };
  37.  
  38. template<typename pp, typename qq> struct matches<pp, pp, qq> {
  39.   enum { value = 2 };
  40. };
  41.  
  42. template<typename pp, typename qq> struct matches<pp, qq, pp> {
  43.   enum { value = 2 };
  44. };
  45.  
  46. template<typename pp> struct matches<pp, pp, pp> {
  47.   enum { value = 3 };
  48. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement