Created
September 15, 2015 11:21
-
-
Save kdungs/91185c4da721d5603cc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <boost/serialization/strong_typedef.hpp> | |
BOOST_STRONG_TYPEDEF(double, Time) | |
BOOST_STRONG_TYPEDEF(double, Distance) | |
BOOST_STRONG_TYPEDEF(double, Velocity) | |
Velocity calculateVelocity(Distance d, Time t) { | |
return Velocity{static_cast<double>(d) / static_cast<double>(t)}; | |
} | |
int main() { | |
// auto v = calculateVelocity(10.0, 5.0); // What is this? What is 10? What is 5? -> Compiler Error! | |
auto v = calculateVelocity(Distance{10.0}, Time{5.0}); | |
std::cout << static_cast<double>(v) << '\n'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The overhead of casting is (theoretically) only on library side. For the user, it is fully transparent. They only use code as written in main. What could be of use is a general overload for streaming operators or even calculations…
I could think of something like
(not tested)