boost_no_sfinae.ipp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // (C) Copyright Eric Friedman 2003.
  2. // Some modifications by Jeremiah Willcock and Jaakko Jarvi.
  3. // Use, modification, and distribution is subject to the Boost Software
  4. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // MACRO: BOOST_NO_SFINAE
  7. // TITLE: SFINAE (substitution failure is not an error)
  8. // DESCRIPTION: SFINAE not supported.
  9. namespace boost_no_sfinae {
  10. namespace f1_a {
  11. template <typename T>
  12. int f1(T*, float)
  13. {
  14. return 0;
  15. }
  16. } using f1_a::f1;
  17. namespace f1_b {
  18. template <typename T>
  19. int f1(T*, int, typename T::int_* = 0)
  20. {
  21. return 1;
  22. }
  23. } using f1_b::f1;
  24. namespace f2_a {
  25. template <typename T>
  26. int f2(T*, float)
  27. {
  28. return 2;
  29. }
  30. } using f2_a::f2;
  31. namespace f2_b {
  32. template <typename T>
  33. typename T::int_ f2(T*, int)
  34. {
  35. return 3;
  36. }
  37. } using f2_b::f2;
  38. struct test_t
  39. {
  40. typedef int int_;
  41. };
  42. struct test2_t {};
  43. int test()
  44. {
  45. test_t* t = 0;
  46. test2_t* t2 = 0;
  47. bool correct =
  48. (f1(t, 0) == 1) &&
  49. (f1(t2, 0) == 0) &&
  50. (f2(t, 0) == 3) &&
  51. (f2(t2, 0) == 2);
  52. return !correct;
  53. }
  54. }