boost_no_sfinae_expr.ipp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // (C) Copyright Mathias Gaunard 2009.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/config for the most recent version.
  6. // MACRO: BOOST_NO_SFINAE_EXPR
  7. // TITLE: SFINAE for expressions
  8. // DESCRIPTION: SFINAE for expressions not supported.
  9. namespace boost_no_sfinae_expr
  10. {
  11. template<typename T>
  12. struct has_foo
  13. {
  14. typedef char NotFound;
  15. struct Found { char x[2]; };
  16. template<int> struct dummy {};
  17. template<class X> static Found test(dummy< sizeof((*(X*)0).foo(), 0) >*);
  18. template<class X> static NotFound test( ... );
  19. static const bool value = (sizeof(Found) == sizeof(test<T>(0)));
  20. };
  21. struct test1 {};
  22. struct test2 { void foo(); };
  23. int test()
  24. {
  25. return has_foo<test1>::value || !has_foo<test2>::value;
  26. }
  27. } // namespace boost_no_sfinae_expr