attribute_of.hpp 2.4 KB

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