Guest User

Untitled

a guest
Dec 22nd, 2011
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. template<class T, class R>
  2. class Matcher {}; //на будущее
  3.  
  4. template<class T, class R>
  5. class RevTuple
  6. {
  7. private:
  8.     T value;
  9.     R rest;
  10. public:
  11.     template<typename N> struct RevType
  12.     {
  13.         typedef RevTuple<T, typename R::template RevType<N>::push_type> push_type;
  14.     };
  15.     typedef T data_type;
  16.     typedef R pop_type;
  17.     RevTuple(const T &val, const R &r):
  18.       value(val), rest(r) {}
  19.     T &GetValue() { return value; }
  20.     R &GetRest() { return rest; }
  21.     template<typename N>
  22.     typename RevType<N>::push_type operator,(const N &val)
  23.     {
  24.         return typename RevType<N>::push_type(value, (rest, val));
  25.     }
  26.     Matcher<T, R> Match()
  27.     {
  28.         return Matcher<T, R>(*this);
  29.     }
  30. };
  31.  
  32. struct empty
  33. {
  34.     template<typename N> struct RevType
  35.     {
  36.         typedef RevTuple<N, empty> push_type;
  37.     };
  38.     typedef empty data_type;
  39.     typedef empty pop_type; //?
  40.     template<typename N>
  41.     typename RevType<N>::push_type operator,(const N &val)
  42.     {
  43.         return typename RevType<N>::push_type(val, *this);
  44.     }
  45. };
  46.  
  47. empty Rule()
  48. {
  49.     return empty();
  50. }
  51.  
  52. int main()
  53. {
  54.     //int a, b, c;
  55.     (Rule(), 1, 2);
  56.     /*if (r.Match(), 1, &a, 3)
  57.         std::cout << "Passed 1: " << a << std::endl;
  58.     if (!(r.Match(), 1, 1, 3))
  59.         std::cout << "Passed 2\n";
  60.     if (r.Match(), a, 2, b)
  61.         std::cout << "Passed 3: " << a << ", " << b << std::endl;*/
  62. }
Advertisement
Add Comment
Please, Sign In to add comment