Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <boost/mpl/vector_c.hpp>
  2. #include <iostream>
  3.  
  4. typedef boost::mpl::vector_c<int,1,0,0,0,0,0,0> mass;
  5. typedef boost::mpl::vector_c<int,0,1,0,0,0,0,0> length; // or position
  6. typedef boost::mpl::vector_c<int,0,0,1,0,0,0,0> time;
  7. typedef boost::mpl::vector_c<int,0,0,0,1,0,0,0> charge;
  8. typedef boost::mpl::vector_c<int,0,0,0,0,1,0,0> temperature;
  9. typedef boost::mpl::vector_c<int,0,0,0,0,0,1,0> intensity;
  10. typedef boost::mpl::vector_c<int,0,0,0,0,0,0,1> angle;
  11.  
  12. template <class T, class Dimensions>
  13. struct quantity
  14. {
  15. explicit quantity(T x)
  16. : m_value(x)
  17. {}
  18.  
  19. T value() const { return m_value; }
  20. private:
  21. T m_value;
  22. };
  23.  
  24. int main()
  25. {
  26. quantity<float,length> l1( 1.0f );
  27. quantity<float,length> l2( 2.0f );
  28. quantity<float,mass> m( 2.0f );
  29.  
  30. l1 = l2;
  31. // l1 = m; // error captured at compile-time
  32.  
  33. std::cout << l1.value() << std::endl;
  34.  
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement