Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / spirit / home / x3 / support / traits / has_attribute.hpp
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 #if defined(_MSC_VER)
13 #pragma once
14 #endif
15
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>
22
23 namespace boost { namespace spirit { namespace x3
24 {
25    struct unused_type;
26 }}}
27
28 namespace boost { namespace spirit { namespace x3 { namespace traits
29 {
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>
37     struct has_attribute;
38     
39     namespace detail
40     {
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>> {};
45
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> {};
51     
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> {};
56     }
57     
58     template <typename Component, typename Context, typename Enable>
59     struct has_attribute : detail::default_has_attribute<Component, Context> {};
60
61 }}}}
62
63 #endif