Guest User

Untitled

a guest
Jan 19th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. #include <type_traits>
  2.  
  3. template <typename T>
  4. typename std::enable_if<std::is_floating_point<T>::value, T>::type float_sum(T value, T value2)
  5. {
  6. return value + value2;
  7. }
  8.  
  9. int main()
  10. {
  11. double x = float_sum(1.0, 2.0); // It compiles
  12. float y = float_sum(2.0, 2.0); // It compiles
  13. int z = float_sum(3, 3); // It doesn't compile
  14. return 0;
  15. }
Add Comment
Please, Sign In to add comment