1 /*=============================================================================
2 Copyright (c) 2001-2014 Joel de Guzman
3 Copyright (c) 2013 Agustin Berge
4 http://spirit.sourceforge.net/
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
16 #include <boost/spirit/home/x3/support/traits/attribute_of.hpp>
17 #include <boost/spirit/home/x3/support/utility/sfinae.hpp>
18 #include <boost/mpl/bool.hpp>
19 #include <boost/mpl/not.hpp>
20 #include <boost/type_traits/is_same.hpp>
21 #include <boost/utility/enable_if.hpp>
23 namespace boost { namespace spirit { namespace x3
28 namespace boost { namespace spirit { namespace x3 { namespace traits
30 ///////////////////////////////////////////////////////////////////////////
31 // Whether a component has an attribute. By default, this compares the
32 // component attribute against unused_type. If the component provides a
33 // nested constant expression has_attribute as a hint, that value is used
34 // instead. Components may specialize this.
35 ///////////////////////////////////////////////////////////////////////////
36 template <typename Component, typename Context, typename Enable = void>
41 template <typename Component, typename Context, typename Enable = void>
42 struct default_has_attribute
43 : mpl::not_<is_same<unused_type,
44 typename attribute_of<Component, Context>::type>> {};
46 template <typename Component, typename Context>
47 struct default_has_attribute<Component, Context,
48 typename disable_if_substitution_failure<
49 mpl::bool_<Component::has_attribute>>::type>
50 : mpl::bool_<Component::has_attribute> {};
52 template <typename Component, typename Context>
53 struct default_has_attribute<Component, Context,
54 typename enable_if_c<Component::is_pass_through_unary>::type>
55 : has_attribute<typename Component::subject_type, Context> {};
58 template <typename Component, typename Context, typename Enable>
59 struct has_attribute : detail::default_has_attribute<Component, Context> {};