/Src/Dependencies/Boost/libs/parameter/test/optional_deduced_sfinae.cpp

http://hadesmem.googlecode.com/ · C++ · 73 lines · 47 code · 18 blank · 8 comment · 3 complexity · e1af85d144c0c06c1d484288d2b21083 MD5 · raw file

  1. // Copyright Daniel Wallin 2006. Use, modification and distribution is
  2. // subject to the Boost Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #include <boost/parameter/preprocessor.hpp>
  5. #include <boost/parameter/name.hpp>
  6. #include <boost/type_traits/is_convertible.hpp>
  7. #include <boost/tuple/tuple.hpp>
  8. #include <string>
  9. #include "basics.hpp"
  10. #include <boost/utility/enable_if.hpp>
  11. namespace test {
  12. namespace mpl = boost::mpl;
  13. using mpl::_;
  14. using boost::is_convertible;
  15. BOOST_PARAMETER_NAME(x)
  16. // Sun has problems with this syntax:
  17. //
  18. // template1< r* ( template2<x> ) >
  19. //
  20. // Workaround: factor template2<x> into a separate typedef
  21. #if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580))
  22. typedef is_convertible<_,char const*> predicate;
  23. BOOST_PARAMETER_FUNCTION((int), sfinae, tag,
  24. (deduced
  25. (optional (x, *(predicate), 0))
  26. )
  27. )
  28. {
  29. return 1;
  30. }
  31. #else
  32. BOOST_PARAMETER_FUNCTION((int), sfinae, tag,
  33. (deduced
  34. (optional (x, *(is_convertible<_,char const*>), 0))
  35. )
  36. )
  37. {
  38. return 1;
  39. }
  40. #endif
  41. template<class A0>
  42. typename boost::enable_if<boost::is_same<int,A0>, int>::type
  43. sfinae(A0 const& a0)
  44. {
  45. return 0;
  46. }
  47. } // namespace test
  48. int main()
  49. {
  50. using namespace test;
  51. assert(sfinae() == 1);
  52. assert(sfinae("foo") == 1);
  53. assert(sfinae(1) == 0);
  54. return 0;
  55. }