variant_has_substitute.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*=============================================================================
  2. Copyright (c) 2001-2014 Joel de Guzman
  3. http://spirit.sourceforge.net/
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. =============================================================================*/
  7. #if !defined(BOOST_SPIRIT_X3_VARIANT_HAS_SUBSTITUTE_APR_18_2014_925AM)
  8. #define BOOST_SPIRIT_X3_VARIANT_HAS_SUBSTITUTE_APR_18_2014_925AM
  9. #include <boost/spirit/home/x3/support/traits/is_substitute.hpp>
  10. #include <boost/mpl/find.hpp>
  11. namespace boost { namespace spirit { namespace x3 { namespace traits
  12. {
  13. template <typename Variant, typename Attribute>
  14. struct variant_has_substitute_impl
  15. {
  16. // Find a type from the variant that can be a substitute for Attribute.
  17. // return true_ if one is found, else false_
  18. typedef Variant variant_type;
  19. typedef typename variant_type::types types;
  20. typedef typename mpl::end<types>::type end;
  21. typedef typename mpl::find<types, Attribute>::type iter_1;
  22. typedef typename
  23. mpl::eval_if<
  24. is_same<iter_1, end>,
  25. mpl::find_if<types, traits::is_substitute<mpl::_1, Attribute>>,
  26. mpl::identity<iter_1>
  27. >::type
  28. iter;
  29. typedef mpl::not_<is_same<iter, end>> type;
  30. };
  31. template <typename Variant, typename Attribute>
  32. struct variant_has_substitute
  33. : variant_has_substitute_impl<Variant, Attribute>::type {};
  34. template <typename Attribute>
  35. struct variant_has_substitute<unused_type, Attribute> : mpl::true_ {};
  36. template <typename Attribute>
  37. struct variant_has_substitute<unused_type const, Attribute> : mpl::true_ {};
  38. }}}}
  39. #endif