element_index.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //-----------------------------------------------------------------------------
  2. // boost variant/detail/element_index.hpp header file
  3. // See http://www.boost.org for updates, documentation, and revision history.
  4. //-----------------------------------------------------------------------------
  5. //
  6. // Copyright (c) 2014-2019 Antony Polukhin
  7. //
  8. // Distributed under the Boost Software License, Version 1.0. (See
  9. // accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #ifndef BOOST_VARIANT_DETAIL_ELEMENT_INDEX_HPP
  12. #define BOOST_VARIANT_DETAIL_ELEMENT_INDEX_HPP
  13. #include <boost/config.hpp>
  14. #include <boost/variant/recursive_wrapper_fwd.hpp>
  15. #include <boost/variant/variant_fwd.hpp>
  16. #include <boost/type_traits/remove_cv.hpp>
  17. #include <boost/type_traits/remove_reference.hpp>
  18. #include <boost/mpl/find_if.hpp>
  19. namespace boost { namespace detail { namespace variant {
  20. template <class VariantElement, class T>
  21. struct variant_element_functor :
  22. boost::mpl::or_<
  23. boost::is_same<VariantElement, T>,
  24. boost::is_same<VariantElement, boost::recursive_wrapper<T> >,
  25. boost::is_same<VariantElement, T& >
  26. >
  27. {};
  28. template <class Types, class T>
  29. struct element_iterator_impl :
  30. boost::mpl::find_if<
  31. Types,
  32. boost::mpl::or_<
  33. variant_element_functor<boost::mpl::_1, T>,
  34. variant_element_functor<boost::mpl::_1, typename boost::remove_cv<T>::type >
  35. >
  36. >
  37. {};
  38. template <class Variant, class T>
  39. struct element_iterator :
  40. element_iterator_impl< typename Variant::types, typename boost::remove_reference<T>::type >
  41. {};
  42. template <class Variant, class T>
  43. struct holds_element :
  44. boost::mpl::not_<
  45. boost::is_same<
  46. typename boost::mpl::end<typename Variant::types>::type,
  47. typename element_iterator<Variant, T>::type
  48. >
  49. >
  50. {};
  51. }}} // namespace boost::detail::variant
  52. #endif // BOOST_VARIANT_DETAIL_ELEMENT_INDEX_HPP