sfinae_friendly.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*=============================================================================
  2. Copyright (c) 2015 Kohei Takahashi
  3. Use modification and distribution are 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. ==============================================================================*/
  7. #ifndef FUSION_TEST_SFINAE_FRIENDLY_HPP
  8. #define FUSION_TEST_SFINAE_FRIENDLY_HPP
  9. #include <boost/config.hpp>
  10. #include <boost/mpl/bool.hpp>
  11. #include <boost/mpl/assert.hpp>
  12. #include <boost/utility/result_of.hpp>
  13. #include <boost/core/enable_if.hpp>
  14. #if !defined(BOOST_NO_SFINAE) && defined(BOOST_RESULT_OF_USE_DECLTYPE)
  15. #include <boost/fusion/container/vector.hpp>
  16. namespace sfinae_friendly
  17. {
  18. template <typename> struct arg_;
  19. template <typename R, typename T> struct arg_<R(T)> { typedef T type; };
  20. template <typename Traits, typename = void>
  21. struct check
  22. : boost::mpl::true_ { };
  23. template <typename Traits>
  24. struct check<Traits, typename boost::enable_if_has_type<typename Traits::type>::type>
  25. : boost::mpl::false_ { };
  26. struct unspecified {};
  27. typedef boost::fusion::vector<> v0;
  28. typedef boost::fusion::vector<unspecified> v1;
  29. typedef boost::fusion::vector<unspecified, unspecified> v2;
  30. typedef boost::fusion::vector<unspecified, unspecified, unspecified> v3;
  31. }
  32. #define SFINAE_FRIENDLY_ASSERT(Traits) \
  33. BOOST_MPL_ASSERT((::sfinae_friendly::check<typename ::sfinae_friendly::arg_<void Traits>::type>))
  34. #else
  35. #define SFINAE_FRIENDLY_ASSERT(Traits) \
  36. BOOST_MPL_ASSERT((boost::mpl::true_))
  37. #endif
  38. #endif // FUSION_TEST_SFINAE_FRIENDLY_HPP