mp_defer.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #ifndef BOOST_TYPE_TRAITS_DETAIL_MP_DEFER_HPP_INCLUDED
  2. #define BOOST_TYPE_TRAITS_DETAIL_MP_DEFER_HPP_INCLUDED
  3. //
  4. // Copyright 2015 Peter Dimov
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt
  9. //
  10. #include <boost/type_traits/integral_constant.hpp>
  11. #include <boost/type_traits/conditional.hpp>
  12. namespace boost
  13. {
  14. namespace type_traits_detail
  15. {
  16. // mp_valid
  17. // implementation by Bruno Dutra (by the name is_evaluable)
  18. template<template<class...> class F, class... T>
  19. struct mp_valid_impl
  20. {
  21. template<template<class...> class G, class = G<T...>>
  22. static boost::true_type check_s(int);
  23. template<template<class...> class>
  24. static boost::false_type check_s(...);
  25. using type = decltype(check_s<F>(0));
  26. };
  27. template<template<class...> class F, class... T>
  28. using mp_valid = typename mp_valid_impl<F, T...>::type;
  29. // mp_defer
  30. struct mp_empty
  31. {
  32. };
  33. template<template<class...> class F, class... T> struct mp_defer_impl
  34. {
  35. using type = F<T...>;
  36. };
  37. template<template<class...> class F, class... T> using mp_defer = typename boost::conditional<mp_valid<F, T...>::value, mp_defer_impl<F, T...>, mp_empty>::type;
  38. } // namespace type_traits_detail
  39. } // namespace boost
  40. #endif // #ifndef BOOST_TYPE_TRAITS_DETAIL_MP_DEFER_HPP_INCLUDED