| 1 | // Boost.TypeErasure library |
| 2 | // |
| 3 | // Copyright 2018 Steven Watanabe |
| 4 | // |
| 5 | // Distributed under the Boost Software License Version 1.0. (See |
| 6 | // accompanying file LICENSE_1_0.txt or copy at |
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
| 8 | // |
| 9 | // $Id$ |
| 10 | |
| 11 | #ifndef BOOST_TYPE_ERASURE_DETAIL_META_HPP_INCLUDED |
| 12 | #define BOOST_TYPE_ERASURE_DETAIL_META_HPP_INCLUDED |
| 13 | |
| 14 | #include <boost/config.hpp> |
| 15 | |
| 16 | |
| 17 | #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \ |
| 18 | !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) && \ |
| 19 | /* MSVC 14.0 breaks down in the template alias quagmire. */ \ |
| 20 | !BOOST_WORKAROUND(BOOST_MSVC, <= 1900) |
| 21 | |
| 22 | #define BOOST_TYPE_ERASURE_USE_MP11 |
| 23 | |
| 24 | #include <boost/mp11/list.hpp> |
| 25 | #include <boost/mp11/map.hpp> |
| 26 | #include <boost/mp11/set.hpp> |
| 27 | #include <boost/mp11/algorithm.hpp> |
| 28 | #include <boost/mp11/function.hpp> |
| 29 | #include <boost/mp11/mpl.hpp> |
| 30 | |
| 31 | namespace boost { |
| 32 | namespace type_erasure { |
| 33 | namespace detail { |
| 34 | |
| 35 | struct mp11_list_inserter |
| 36 | { |
| 37 | template<class L, class T> |
| 38 | using apply = ::boost::mpl::identity< ::boost::mp11::mp_push_back<L, T> >; |
| 39 | }; |
| 40 | |
| 41 | template<class T> |
| 42 | struct make_mp_list_impl |
| 43 | { |
| 44 | typedef typename ::boost::mpl::fold< |
| 45 | T, |
| 46 | ::boost::mp11::mp_list<>, |
| 47 | ::boost::type_erasure::detail::mp11_list_inserter |
| 48 | >::type type; |
| 49 | }; |
| 50 | |
| 51 | template<class... T> |
| 52 | struct make_mp_list_impl< ::boost::mp11::mp_list<T...> > |
| 53 | { |
| 54 | typedef ::boost::mp11::mp_list<T...> type; |
| 55 | }; |
| 56 | |
| 57 | template<class T> |
| 58 | using make_mp_list = typename make_mp_list_impl<T>::type; |
| 59 | |
| 60 | template<bool> |
| 61 | struct eval_if_impl; |
| 62 | |
| 63 | template<> |
| 64 | struct eval_if_impl<true> |
| 65 | { |
| 66 | template<template<class...> class T, template<class...> class F, class... A> |
| 67 | using apply = T<A...>; |
| 68 | }; |
| 69 | |
| 70 | template<> |
| 71 | struct eval_if_impl<false> |
| 72 | { |
| 73 | template<template<class...> class T, template<class...> class F, class... A> |
| 74 | using apply = F<A...>; |
| 75 | }; |
| 76 | |
| 77 | template<bool B, template<class...> class T, template<class...> class F, class... A> |
| 78 | using eval_if = typename ::boost::type_erasure::detail::eval_if_impl<B>::template apply<T, F, A...>; |
| 79 | |
| 80 | template<class T0, class...> |
| 81 | using first = T0; |
| 82 | |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | #endif |
| 88 | |
| 89 | #endif |
| 90 | |