Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <boost/mpl/vector_c.hpp>
- #include <iostream>
- typedef boost::mpl::vector_c<int,1,0,0,0,0,0,0> mass;
- typedef boost::mpl::vector_c<int,0,1,0,0,0,0,0> length; // or position
- typedef boost::mpl::vector_c<int,0,0,1,0,0,0,0> time;
- typedef boost::mpl::vector_c<int,0,0,0,1,0,0,0> charge;
- typedef boost::mpl::vector_c<int,0,0,0,0,1,0,0> temperature;
- typedef boost::mpl::vector_c<int,0,0,0,0,0,1,0> intensity;
- typedef boost::mpl::vector_c<int,0,0,0,0,0,0,1> angle;
- template <class T, class Dimensions>
- struct quantity
- {
- explicit quantity(T x)
- : m_value(x)
- {}
- T value() const { return m_value; }
- private:
- T m_value;
- };
- int main()
- {
- quantity<float,length> l1( 1.0f );
- quantity<float,length> l2( 2.0f );
- quantity<float,mass> m( 2.0f );
- l1 = l2;
- // l1 = m; // error captured at compile-time
- std::cout << l1.value() << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement