Created
July 24, 2012 22:43
-
-
Save chriswailes/3173150 to your computer and use it in GitHub Desktop.
Casting Problems with Templates
This file contains hidden or 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
class MyClass { | |
template <typename IntType> | |
inline operator typename std::enable_if<std::is_integral<IntType>::value, IntType>::type () { | |
// Integer specific code. | |
} | |
template <typename FloatType> | |
inline operator typename std::enable_if<std::is_floating_point<FloatType>::value, FloatType>::type () { | |
// Float specific code. | |
} | |
}; | |
void* foo = malloc(...); | |
MyClass bar(...); | |
*reinterpret_cast<uint8_t*>(foo) = static_cast<uint8_t>(bar); |
Author
chriswailes
commented
Jul 24, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment