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