Advertisement
Guest User

A try of logic with C++ templates :)

a guest
Sep 18th, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. template<typename prop_name>
  2. class Property
  3. {
  4. public:
  5.     void easifyEquation(const char* equation) {
  6.         // property is maybe true, but not known
  7.         // so don't easify the equation, do nothing!
  8.     }
  9. };
  10.  
  11. template<typename prop_type>
  12. class TrueProperty
  13. {
  14.     prop_type prop_implementation;
  15. public:
  16.     void easifyEquation(const char* equation) {
  17.         prop_implementation.easifyEquation(equation);
  18.     }
  19. };
  20.  
  21. class IsPID {
  22.     void easifyEquation(const char* equation) {}
  23. };
  24. class IsUFD{};
  25. class IsDedekind{};
  26.  
  27. class BaseRing
  28. {
  29. public:
  30.     Property<IsUFD> ufd;
  31.     Property<IsDedekind> dedekind;
  32.     Property<IsPID> pid;
  33. };
  34.  
  35. class UFD : public BaseRing
  36. {
  37. public:
  38.     TrueProperty<IsUFD> ufd;
  39. };
  40.  
  41. class Dedekind : public BaseRing
  42. {
  43. public:
  44.     TrueProperty<IsDedekind> dedekind;
  45. };
  46.  
  47. class Both : public BaseRing
  48. {
  49. public:
  50.     TrueProperty<IsUFD> ufd;
  51.     TrueProperty<IsDedekind> dedekind;
  52.     // shall have the isPID property implicitly
  53. };
  54.  
  55. void do_experiments()
  56. {
  57.     UFD ufd;
  58.     Both both;
  59.  
  60.     /*
  61.         Let's easify an equation
  62.     */
  63.     const char* equation;
  64.  
  65.     // both is a pid, since ufd and dedekind implies pid
  66.     // thus, we can easify equations with the pid property
  67.     both.pid.easifyEquation(equation);
  68.  
  69.     // the ufd is not (necessary) a PID
  70.     // thus, easifying the equation like in PIDs shall not do anything.
  71.     ufd.pid.easifyEquation(equation);
  72. }
  73.  
  74. int main() {
  75.     do_experiments();
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement