has_attribute.hpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_HAS_ATTRIBUTE_JUN_6_2012_1714PM)
  9. #define BOOST_SPIRIT_X3_HAS_ATTRIBUTE_JUN_6_2012_1714PM
  10. #include <boost/spirit/home/x3/support/traits/attribute_of.hpp>
  11. #include <boost/spirit/home/x3/support/utility/sfinae.hpp>
  12. #include <boost/mpl/bool.hpp>
  13. #include <boost/mpl/not.hpp>
  14. #include <boost/type_traits/is_same.hpp>
  15. #include <boost/utility/enable_if.hpp>
  16. namespace boost { namespace spirit { namespace x3
  17. {
  18. struct unused_type;
  19. }}}
  20. namespace boost { namespace spirit { namespace x3 { namespace traits
  21. {
  22. ///////////////////////////////////////////////////////////////////////////
  23. // Whether a component has an attribute. By default, this compares the
  24. // component attribute against unused_type. If the component provides a
  25. // nested constant expression has_attribute as a hint, that value is used
  26. // instead. Components may specialize this.
  27. ///////////////////////////////////////////////////////////////////////////
  28. template <typename Component, typename Context, typename Enable = void>
  29. struct has_attribute;
  30. namespace detail
  31. {
  32. template <typename Component, typename Context, typename Enable = void>
  33. struct default_has_attribute
  34. : mpl::not_<is_same<unused_type,
  35. typename attribute_of<Component, Context>::type>> {};
  36. template <typename Component, typename Context>
  37. struct default_has_attribute<Component, Context,
  38. typename disable_if_substitution_failure<
  39. mpl::bool_<Component::has_attribute>>::type>
  40. : mpl::bool_<Component::has_attribute> {};
  41. template <typename Component, typename Context>
  42. struct default_has_attribute<Component, Context,
  43. typename enable_if_c<Component::is_pass_through_unary>::type>
  44. : has_attribute<typename Component::subject_type, Context> {};
  45. }
  46. template <typename Component, typename Context, typename Enable>
  47. struct has_attribute : detail::default_has_attribute<Component, Context> {};
  48. }}}}
  49. #endif