1 /*============================================================================= 2 Copyright (c) 2001-2014 Joel de Guzman 3 Copyright (c) 2013 Agustin Berge 4 http://spirit.sourceforge.net/ 5 6 Distributed under the Boost Software License, Version 1.0. (See accompanying 7 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 =============================================================================*/ 9 #if !defined(BOOST_SPIRIT_X3_HAS_ATTRIBUTE_JUN_6_2012_1714PM) 10 #define BOOST_SPIRIT_X3_HAS_ATTRIBUTE_JUN_6_2012_1714PM 11 12 #include <boost/spirit/home/x3/support/traits/attribute_of.hpp> 13 #include <boost/spirit/home/x3/support/utility/sfinae.hpp> 14 #include <boost/mpl/bool.hpp> 15 #include <boost/mpl/not.hpp> 16 #include <boost/type_traits/is_same.hpp> 17 #include <boost/utility/enable_if.hpp> 18 19 namespace boost { namespace spirit { namespace x3 20 { 21 struct unused_type; 22 }}} 23 24 namespace boost { namespace spirit { namespace x3 { namespace traits 25 { 26 /////////////////////////////////////////////////////////////////////////// 27 // Whether a component has an attribute. By default, this compares the 28 // component attribute against unused_type. If the component provides a 29 // nested constant expression has_attribute as a hint, that value is used 30 // instead. Components may specialize this. 31 /////////////////////////////////////////////////////////////////////////// 32 template <typename Component, typename Context, typename Enable = void> 33 struct has_attribute; 34 35 namespace detail 36 { 37 template <typename Component, typename Context, typename Enable = void> 38 struct default_has_attribute 39 : mpl::not_<is_same<unused_type, 40 typename attribute_of<Component, Context>::type>> {}; 41 42 template <typename Component, typename Context> 43 struct default_has_attribute<Component, Context, 44 typename disable_if_substitution_failure< 45 mpl::bool_<Component::has_attribute>>::type> 46 : mpl::bool_<Component::has_attribute> {}; 47 48 template <typename Component, typename Context> 49 struct default_has_attribute<Component, Context, 50 typename enable_if_c<Component::is_pass_through_unary>::type> 51 : has_attribute<typename Component::subject_type, Context> {}; 52 } 53 54 template <typename Component, typename Context, typename Enable> 55 struct has_attribute : detail::default_has_attribute<Component, Context> {}; 56 57 }}}} 58 59 #endif 60