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_ATTRIBUTE_OF_JAN_7_2012_0914AM) 10 #define BOOST_SPIRIT_X3_ATTRIBUTE_OF_JAN_7_2012_0914AM 11 12 #include <boost/spirit/home/x3/support/utility/sfinae.hpp> 13 #include <boost/mpl/identity.hpp> 14 #include <boost/utility/enable_if.hpp> 15 16 namespace boost { namespace spirit { namespace x3 { namespace traits 17 { 18 /////////////////////////////////////////////////////////////////////////// 19 // Get the attribute type of a component. By default, this gets the 20 // Component's attribute_type typedef or instantiates a nested attribute 21 // metafunction. Components may specialize this if such an attribute_type 22 // is not readily available (e.g. expensive to compute at compile time). 23 /////////////////////////////////////////////////////////////////////////// 24 template <typename Component, typename Context, typename Enable = void> 25 struct attribute_of; 26 27 namespace detail 28 { 29 template <typename Component, typename Context, typename Enable = void> 30 struct default_attribute_of; 31 32 template <typename Component, typename Context> 33 struct default_attribute_of<Component, Context, 34 typename disable_if_substitution_failure< 35 typename Component::attribute_type>::type> 36 : mpl::identity<typename Component::attribute_type> {}; 37 38 template <typename Component, typename Context> 39 struct default_attribute_of<Component, Context, 40 typename disable_if_substitution_failure< 41 typename Component::template attribute<Context>::type>::type> 42 : Component::template attribute<Context> {}; 43 44 template <typename Component, typename Context> 45 struct default_attribute_of<Component, Context, 46 typename enable_if_c<Component::is_pass_through_unary>::type> 47 : attribute_of<typename Component::subject_type, Context>{}; 48 } 49 50 template <typename Component, typename Context, typename Enable> 51 struct attribute_of : detail::default_attribute_of<Component, Context> {}; 52 }}}} 53 54 #endif 55