Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <type_traits>
- template <typename T>
- typename std::enable_if<std::is_floating_point<T>::value, T>::type float_sum(T value, T value2)
- {
- return value + value2;
- }
- int main()
- {
- double x = float_sum(1.0, 2.0); // It compiles
- float y = float_sum(2.0, 2.0); // It compiles
- int z = float_sum(3, 3); // It doesn't compile
- return 0;
- }
Add Comment
Please, Sign In to add comment