fork(4) download
  1. #include <algorithm>
  2. #include <functional>
  3. #include <iostream>
  4. #include <memory>
  5. #include <string>
  6. #include <type_traits>
  7. #include <utility>
  8.  
  9.  
  10. struct field
  11. {
  12. template<typename TDataType, typename = typename
  13. std::enable_if< std::is_fundamental<TDataType>::value &&
  14. std::is_same<TDataType, std::nullptr_t>::value == false &&
  15. std::is_same<TDataType, void>::value == false>::type>
  16. void set_data(TDataType data, size_t index = 0)
  17. {
  18. std::cout << "Fundamental\n";
  19. }
  20.  
  21. template<typename TDataType, typename = void, typename = typename
  22. std::enable_if< std::is_same<std::string, TDataType>::value ||
  23. std::is_same<char const *, TDataType>::value>::type>
  24. void set_data(TDataType data, size_t index = 0)
  25. {
  26. std::cout << "String\n";
  27. }
  28. };
  29.  
  30.  
  31. int main()
  32. {
  33. field f;
  34. f.set_data("abc");
  35. f.set_data(7);
  36. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
String
Fundamental