find.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Copyright (c) 2011 Eric Niebler
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #if !defined(FUSION_FIND_05052005_1107)
  8. #define FUSION_FIND_05052005_1107
  9. #include <boost/fusion/support/config.hpp>
  10. #include <boost/fusion/algorithm/query/find_if_fwd.hpp>
  11. #include <boost/fusion/algorithm/query/detail/find_if.hpp>
  12. #include <boost/fusion/algorithm/query/detail/segmented_find.hpp>
  13. #include <boost/fusion/iterator/key_of.hpp>
  14. #include <boost/fusion/iterator/value_of.hpp>
  15. #include <boost/fusion/support/category_of.hpp>
  16. #include <boost/fusion/support/is_segmented.hpp>
  17. #include <boost/mpl/if.hpp>
  18. #include <boost/mpl/placeholders.hpp>
  19. #include <boost/type_traits/is_same.hpp>
  20. #include <boost/type_traits/is_const.hpp>
  21. #include <boost/utility/enable_if.hpp>
  22. namespace boost { namespace fusion
  23. {
  24. namespace result_of
  25. {
  26. template <typename Sequence, typename T>
  27. struct find
  28. : mpl::if_<
  29. traits::is_segmented<Sequence>
  30. , detail::result_of_segmented_find<Sequence, T>
  31. , detail::result_of_find_if<
  32. Sequence,
  33. is_same<
  34. typename mpl::if_<
  35. traits::is_associative<Sequence>
  36. , key_of<mpl::_1>
  37. , value_of<mpl::_1>
  38. >::type
  39. , T
  40. >
  41. >
  42. >::type
  43. {};
  44. }
  45. template <typename T, typename Sequence>
  46. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  47. inline typename
  48. lazy_disable_if<
  49. is_const<Sequence>
  50. , result_of::find<Sequence, T>
  51. >::type const
  52. find(Sequence& seq)
  53. {
  54. typedef typename result_of::find<Sequence, T>::filter filter;
  55. return filter::call(seq);
  56. }
  57. template <typename T, typename Sequence>
  58. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  59. inline typename result_of::find<Sequence const, T>::type const
  60. find(Sequence const& seq)
  61. {
  62. typedef typename result_of::find<Sequence const, T>::filter filter;
  63. return filter::call(seq);
  64. }
  65. }}
  66. #endif