diff --git a/include/boost/mp11.hpp b/include/boost/mp11.hpp index 5e45939..dcf0204 100644 --- a/include/boost/mp11.hpp +++ b/include/boost/mp11.hpp @@ -18,5 +18,6 @@ #include #include #include +#include #endif // #ifndef BOOST_MP11_HPP_INCLUDED diff --git a/include/boost/mp11/mpl.hpp b/include/boost/mp11/mpl.hpp new file mode 100644 index 0000000..0e836cb --- /dev/null +++ b/include/boost/mp11/mpl.hpp @@ -0,0 +1,175 @@ +#ifndef BOOST_MP11_MPL_HPP_INCLUDED +#define BOOST_MP11_MPL_HPP_INCLUDED + +// Copyright 2017 Peter Dimov. +// +// Distributed under the Boost Software License, Version 1.0. +// +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include + +namespace boost +{ +namespace mpl +{ + +struct forward_iterator_tag; + +namespace aux +{ + +struct mp11_tag {}; + +template struct mp11_iterator +{ + using category = forward_iterator_tag; + + using type = mp11::mp_first; + using next = mp11_iterator>; +}; + +} // namespace aux + +// at + +template< typename Tag > struct at_impl; + +template<> struct at_impl +{ + template struct apply + { + using type = mp11::mp_at; + }; +}; + +// back + +template< typename Tag > struct back_impl; + +template<> struct back_impl +{ + template struct apply + { + using N = mp11::mp_size; + using type = mp11::mp_at_c; + }; +}; + +// begin + +template< typename Tag > struct begin_impl; + +template<> struct begin_impl +{ + template struct apply + { + using type = aux::mp11_iterator; + }; +}; + +// clear + +template< typename Tag > struct clear_impl; + +template<> struct clear_impl +{ + template struct apply + { + using type = mp11::mp_clear; + }; +}; + +// end + +template< typename Tag > struct end_impl; + +template<> struct end_impl +{ + template struct apply + { + using type = aux::mp11_iterator>; + }; +}; + +// front + +template< typename Tag > struct front_impl; + +template<> struct front_impl +{ + template struct apply + { + using type = mp11::mp_front; + }; +}; + +// pop_front + +template< typename Tag > struct pop_front_impl; + +template<> struct pop_front_impl +{ + template struct apply + { + using type = mp11::mp_pop_front; + }; +}; + +// push_back + +template< typename Tag > struct push_back_impl; + +template<> struct push_back_impl +{ + template struct apply + { + using type = mp11::mp_push_back; + }; +}; + +// push_front + +template< typename Tag > struct push_front_impl; + +template<> struct push_front_impl +{ + template struct apply + { + using type = mp11::mp_push_front; + }; +}; + +// sequence_tag + +template< typename Sequence > struct sequence_tag; + +template struct sequence_tag> +{ + using type = aux::mp11_tag; +}; + +template struct sequence_tag> +{ + using type = aux::mp11_tag; +}; + +// size + +template< typename Tag > struct size_impl; + +template<> struct size_impl +{ + template struct apply + { + using type = mp11::mp_size; + }; +}; + +} // namespace mpl +} // namespace boost + +#endif // #ifndef BOOST_MP11_MPL_HPP_INCLUDED diff --git a/test/Jamfile b/test/Jamfile index 210a3da..ead58f0 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -131,3 +131,6 @@ run mp_bind.cpp : : : $(REQ) ; run mp_bind_q.cpp : : : $(REQ) ; run mp_bind_front.cpp : : : $(REQ) ; run mp_bind_back.cpp : : : $(REQ) ; + +# mpl +run mpl.cpp : : : $(REQ) ; diff --git a/test/mpl.cpp b/test/mpl.cpp new file mode 100644 index 0000000..5e9551e --- /dev/null +++ b/test/mpl.cpp @@ -0,0 +1,108 @@ + +// Copyright 2017 Peter Dimov. +// +// Distributed under the Boost Software License, Version 1.0. +// +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt + + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +template using add_pointer_t = typename std::add_pointer::type; + +template void test() +{ + namespace mpl = boost::mpl; + using namespace boost::mp11; + + // intrinsics + + BOOST_TEST_TRAIT_TRUE((std::is_same>::type, mp_at_c>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>::type, mp_at_c>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>::type, mp_at_c>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::type, mp_at_c>)); + BOOST_TEST_TRAIT_TRUE((std::is_same::type, mp_at_c>)); + BOOST_TEST_TRAIT_TRUE((std::is_same::type, mp_at_c>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::type, float>)); + + BOOST_TEST_EQ((mpl::distance::type, typename mpl::end::type>::type::value), mp_size::value); + + BOOST_TEST_TRAIT_TRUE((std::is_same::type, mp_clear>)); + + BOOST_TEST_TRAIT_FALSE((typename mpl::empty::type)); + BOOST_TEST_TRAIT_TRUE((typename mpl::empty>::type)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::type>::type, mp_pop_front>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::type, mp_front>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::type, void>::type, mp_push_front>)); + BOOST_TEST_TRAIT_TRUE((std::is_same::type, void>::type, mp_push_back>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::type, L1>::type, mp_append>)); + + BOOST_TEST_TRAIT_TRUE((typename mpl::is_sequence::type)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::type, mp_pop_front>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::type, mp_push_back>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::type, mp_push_front>)); + + BOOST_TEST_EQ((mpl::size::type::value), mp_size::value); + + // algorithms + + BOOST_TEST_TRAIT_TRUE((std::is_same>::type, mp_transform>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::type, mp_reverse>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::type, mp_remove>)); + + using L2 = typename mpl::copy>>::type; + using L3 = typename mpl::copy>>::type; + + BOOST_TEST_TRAIT_TRUE((std::is_same)); +} + +int main() +{ + using boost::mp11::mp_list; + + test>(); + test>(); // MPL instantiates the tuple, so no 'void' + + return boost::report_errors(); +}