forked from boostorg/mp11
Add MPL support
This commit is contained in:
@ -18,5 +18,6 @@
|
||||
#include <boost/mp11/bind.hpp>
|
||||
#include <boost/mp11/integer_sequence.hpp>
|
||||
#include <boost/mp11/tuple.hpp>
|
||||
#include <boost/mp11/mpl.hpp>
|
||||
|
||||
#endif // #ifndef BOOST_MP11_HPP_INCLUDED
|
||||
|
175
include/boost/mp11/mpl.hpp
Normal file
175
include/boost/mp11/mpl.hpp
Normal file
@ -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 <boost/mp11/list.hpp>
|
||||
#include <boost/mp11/algorithm.hpp>
|
||||
#include <tuple>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace mpl
|
||||
{
|
||||
|
||||
struct forward_iterator_tag;
|
||||
|
||||
namespace aux
|
||||
{
|
||||
|
||||
struct mp11_tag {};
|
||||
|
||||
template<class L> struct mp11_iterator
|
||||
{
|
||||
using category = forward_iterator_tag;
|
||||
|
||||
using type = mp11::mp_first<L>;
|
||||
using next = mp11_iterator<mp11::mp_rest<L>>;
|
||||
};
|
||||
|
||||
} // namespace aux
|
||||
|
||||
// at
|
||||
|
||||
template< typename Tag > struct at_impl;
|
||||
|
||||
template<> struct at_impl<aux::mp11_tag>
|
||||
{
|
||||
template<class L, class I> struct apply
|
||||
{
|
||||
using type = mp11::mp_at<L, I>;
|
||||
};
|
||||
};
|
||||
|
||||
// back
|
||||
|
||||
template< typename Tag > struct back_impl;
|
||||
|
||||
template<> struct back_impl<aux::mp11_tag>
|
||||
{
|
||||
template<class L> struct apply
|
||||
{
|
||||
using N = mp11::mp_size<L>;
|
||||
using type = mp11::mp_at_c<L, N::value - 1>;
|
||||
};
|
||||
};
|
||||
|
||||
// begin
|
||||
|
||||
template< typename Tag > struct begin_impl;
|
||||
|
||||
template<> struct begin_impl<aux::mp11_tag>
|
||||
{
|
||||
template<class L> struct apply
|
||||
{
|
||||
using type = aux::mp11_iterator<L>;
|
||||
};
|
||||
};
|
||||
|
||||
// clear
|
||||
|
||||
template< typename Tag > struct clear_impl;
|
||||
|
||||
template<> struct clear_impl<aux::mp11_tag>
|
||||
{
|
||||
template<class L> struct apply
|
||||
{
|
||||
using type = mp11::mp_clear<L>;
|
||||
};
|
||||
};
|
||||
|
||||
// end
|
||||
|
||||
template< typename Tag > struct end_impl;
|
||||
|
||||
template<> struct end_impl<aux::mp11_tag>
|
||||
{
|
||||
template<class L> struct apply
|
||||
{
|
||||
using type = aux::mp11_iterator<mp11::mp_clear<L>>;
|
||||
};
|
||||
};
|
||||
|
||||
// front
|
||||
|
||||
template< typename Tag > struct front_impl;
|
||||
|
||||
template<> struct front_impl<aux::mp11_tag>
|
||||
{
|
||||
template<class L> struct apply
|
||||
{
|
||||
using type = mp11::mp_front<L>;
|
||||
};
|
||||
};
|
||||
|
||||
// pop_front
|
||||
|
||||
template< typename Tag > struct pop_front_impl;
|
||||
|
||||
template<> struct pop_front_impl<aux::mp11_tag>
|
||||
{
|
||||
template<class L> struct apply
|
||||
{
|
||||
using type = mp11::mp_pop_front<L>;
|
||||
};
|
||||
};
|
||||
|
||||
// push_back
|
||||
|
||||
template< typename Tag > struct push_back_impl;
|
||||
|
||||
template<> struct push_back_impl<aux::mp11_tag>
|
||||
{
|
||||
template<class L, class T> struct apply
|
||||
{
|
||||
using type = mp11::mp_push_back<L, T>;
|
||||
};
|
||||
};
|
||||
|
||||
// push_front
|
||||
|
||||
template< typename Tag > struct push_front_impl;
|
||||
|
||||
template<> struct push_front_impl<aux::mp11_tag>
|
||||
{
|
||||
template<class L, class T> struct apply
|
||||
{
|
||||
using type = mp11::mp_push_front<L, T>;
|
||||
};
|
||||
};
|
||||
|
||||
// sequence_tag
|
||||
|
||||
template< typename Sequence > struct sequence_tag;
|
||||
|
||||
template<class... T> struct sequence_tag<mp11::mp_list<T...>>
|
||||
{
|
||||
using type = aux::mp11_tag;
|
||||
};
|
||||
|
||||
template<class... T> struct sequence_tag<std::tuple<T...>>
|
||||
{
|
||||
using type = aux::mp11_tag;
|
||||
};
|
||||
|
||||
// size
|
||||
|
||||
template< typename Tag > struct size_impl;
|
||||
|
||||
template<> struct size_impl<aux::mp11_tag>
|
||||
{
|
||||
template<class L> struct apply
|
||||
{
|
||||
using type = mp11::mp_size<L>;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace mpl
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_MP11_MPL_HPP_INCLUDED
|
@ -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) ;
|
||||
|
108
test/mpl.cpp
Normal file
108
test/mpl.cpp
Normal file
@ -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 <boost/mp11/mpl.hpp>
|
||||
#include <boost/mp11/list.hpp>
|
||||
|
||||
#include <boost/mpl/at.hpp>
|
||||
#include <boost/mpl/int.hpp>
|
||||
#include <boost/mpl/back.hpp>
|
||||
#include <boost/mpl/begin.hpp>
|
||||
#include <boost/mpl/end.hpp>
|
||||
#include <boost/mpl/distance.hpp>
|
||||
#include <boost/mpl/clear.hpp>
|
||||
#include <boost/mpl/empty.hpp>
|
||||
#include <boost/mpl/erase.hpp>
|
||||
#include <boost/mpl/front.hpp>
|
||||
#include <boost/mpl/insert.hpp>
|
||||
#include <boost/mpl/insert_range.hpp>
|
||||
#include <boost/mpl/is_sequence.hpp>
|
||||
#include <boost/mpl/pop_front.hpp>
|
||||
#include <boost/mpl/push_back.hpp>
|
||||
#include <boost/mpl/push_front.hpp>
|
||||
#include <boost/mpl/size.hpp>
|
||||
#include <boost/mpl/vector.hpp>
|
||||
#include <boost/mpl/transform.hpp>
|
||||
#include <boost/mpl/reverse.hpp>
|
||||
#include <boost/mpl/remove.hpp>
|
||||
#include <boost/mpl/copy.hpp>
|
||||
#include <boost/mpl/back_inserter.hpp>
|
||||
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
|
||||
template<class T> using add_pointer_t = typename std::add_pointer<T>::type;
|
||||
|
||||
template<class L1> void test()
|
||||
{
|
||||
namespace mpl = boost::mpl;
|
||||
using namespace boost::mp11;
|
||||
|
||||
// intrinsics
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::at<L1, mpl::int_<0>>::type, mp_at_c<L1, 0>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::at<L1, mpl::int_<1>>::type, mp_at_c<L1, 1>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::at<L1, mpl::int_<2>>::type, mp_at_c<L1, 2>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::at_c<L1, 0>::type, mp_at_c<L1, 0>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::at_c<L1, 1>::type, mp_at_c<L1, 1>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::at_c<L1, 2>::type, mp_at_c<L1, 2>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::back<L1>::type, float>));
|
||||
|
||||
BOOST_TEST_EQ((mpl::distance<typename mpl::begin<L1>::type, typename mpl::end<L1>::type>::type::value), mp_size<L1>::value);
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::clear<L1>::type, mp_clear<L1>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((typename mpl::empty<L1>::type));
|
||||
BOOST_TEST_TRAIT_TRUE((typename mpl::empty<mp_clear<L1>>::type));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::erase<L1, typename mpl::begin<L1>::type>::type, mp_pop_front<L1>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::front<L1>::type, mp_front<L1>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::insert<L1, typename mpl::begin<L1>::type, void>::type, mp_push_front<L1, void>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::insert<L1, typename mpl::end<L1>::type, void>::type, mp_push_back<L1, void>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::insert_range<L1, typename mpl::end<L1>::type, L1>::type, mp_append<L1, L1>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((typename mpl::is_sequence<L1>::type));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::pop_front<L1>::type, mp_pop_front<L1>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::push_back<L1, char>::type, mp_push_back<L1, char>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::push_front<L1, char>::type, mp_push_front<L1, char>>));
|
||||
|
||||
BOOST_TEST_EQ((mpl::size<L1>::type::value), mp_size<L1>::value);
|
||||
|
||||
// algorithms
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::transform<L1, std::add_pointer<mpl::_1>>::type, mp_transform<add_pointer_t, L1>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::reverse<L1>::type, mp_reverse<L1>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::remove<L1, int>::type, mp_remove<L1, int>>));
|
||||
|
||||
using L2 = typename mpl::copy<L1, mpl::back_inserter<mpl::vector<>>>::type;
|
||||
using L3 = typename mpl::copy<L2, mpl::back_inserter<mp_clear<L1>>>::type;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<L1, L3>));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
using boost::mp11::mp_list;
|
||||
|
||||
test<mp_list<int, void, float>>();
|
||||
test<std::tuple<int, long, float>>(); // MPL instantiates the tuple, so no 'void'
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user