mp_map_find.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef BOOST_MP11_DETAIL_MP_MAP_FIND_HPP_INCLUDED
  2. #define BOOST_MP11_DETAIL_MP_MAP_FIND_HPP_INCLUDED
  3. // Copyright 2015 Peter Dimov.
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. //
  7. // See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt
  9. #include <boost/mp11/utility.hpp>
  10. #include <boost/mp11/detail/config.hpp>
  11. #if BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1930 )
  12. // not exactly good practice, but...
  13. namespace std
  14. {
  15. template<class... _Types> class tuple;
  16. }
  17. #endif
  18. namespace boost
  19. {
  20. namespace mp11
  21. {
  22. // mp_map_find
  23. namespace detail
  24. {
  25. #if !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1930 )
  26. template<class T> using mpmf_wrap = mp_identity<T>;
  27. template<class T> using mpmf_unwrap = typename T::type;
  28. #else
  29. template<class... T> struct mpmf_tuple {};
  30. template<class T> struct mpmf_wrap_impl
  31. {
  32. using type = mp_identity<T>;
  33. };
  34. template<class... T> struct mpmf_wrap_impl< std::tuple<T...> >
  35. {
  36. using type = mp_identity< mpmf_tuple<T...> >;
  37. };
  38. template<class T> using mpmf_wrap = typename mpmf_wrap_impl<T>::type;
  39. template<class T> struct mpmf_unwrap_impl
  40. {
  41. using type = typename T::type;
  42. };
  43. template<class... T> struct mpmf_unwrap_impl< mp_identity< mpmf_tuple<T...> > >
  44. {
  45. using type = std::tuple<T...>;
  46. };
  47. template<class T> using mpmf_unwrap = typename mpmf_unwrap_impl<T>::type;
  48. #endif // #if !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1930 )
  49. template<class M, class K> struct mp_map_find_impl;
  50. template<template<class...> class M, class... T, class K> struct mp_map_find_impl<M<T...>, K>
  51. {
  52. using U = mp_inherit<mpmf_wrap<T>...>;
  53. template<template<class...> class L, class... U> static mp_identity<L<K, U...>> f( mp_identity<L<K, U...>>* );
  54. static mp_identity<void> f( ... );
  55. using type = mpmf_unwrap< decltype( f((U*)0) ) >;
  56. };
  57. } // namespace detail
  58. template<class M, class K> using mp_map_find = typename detail::mp_map_find_impl<M, K>::type;
  59. } // namespace mp11
  60. } // namespace boost
  61. #endif // #ifndef BOOST_MP11_DETAIL_MP_MAP_FIND_HPP_INCLUDED