1
0
forked from boostorg/mp11

Merge branch 'feature/mpl' into develop

This commit is contained in:
Peter Dimov
2017-07-20 22:19:52 +03:00
7 changed files with 356 additions and 0 deletions

View File

@@ -607,6 +607,8 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
<li><a href="#tuple_for_each_tp_f">tuple_for_each(tp, f)</a></li>
</ul>
</li>
<li><a href="#mp11">Convenience Header, &lt;boost/mp11.hpp&gt;</a></li>
<li><a href="#mpl">MPL Support, &lt;boost/mp11/mpl.hpp&gt;</a></li>
</ul>
</li>
<li><a href="#copyright_and_license">Appendix A: Copyright and License</a></li>
@@ -3880,6 +3882,33 @@ expression <code>f(std::get&lt;J&gt;(std::forward&lt;Tp&gt;(tp)))</code> for <co
</div>
</div>
</div>
<div class="sect2">
<h3 id="mp11">Convenience Header, &lt;boost/mp11.hpp&gt;</h3>
<div class="paragraph">
<p>The convenience header <code>&lt;boost/mp11.hpp&gt;</code> includes all of the
headers listed previously in this reference.</p>
</div>
</div>
<div class="sect2">
<h3 id="mpl">MPL Support, &lt;boost/mp11/mpl.hpp&gt;</h3>
<div class="paragraph">
<p>The header <code>&lt;boost/mp11/mpl.hpp&gt;</code>, when included, defines the
necessary support infrastructure for <code>mp_list</code> and <code>std::tuple</code>
to be valid <a href="../../../../libs/mpl">MPL</a> sequences.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<div class="title">Note</div>
</td>
<td class="content">
<code>mpl.hpp</code> is not included by <code>&lt;boost/mp11.hpp&gt;</code>.
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="sect1">

17
doc/mp11/mp11.adoc Normal file
View File

@@ -0,0 +1,17 @@
////
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
////
[#mp11]
# Convenience Header, <boost/mp11.hpp>
:toc:
:toc-title:
:idprefix:
The convenience header `<boost/mp11.hpp>` includes all of the
headers listed previously in this reference.

20
doc/mp11/mpl.adoc Normal file
View File

@@ -0,0 +1,20 @@
////
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
////
[#mpl]
# MPL Support, <boost/mp11/mpl.hpp>
:toc:
:toc-title:
:idprefix:
The header `<boost/mp11/mpl.hpp>`, when included, defines the
necessary support infrastructure for `mp_list` and `std::tuple`
to be valid link:../../../../libs/mpl[MPL] sequences.
NOTE: `mpl.hpp` is not included by `<boost/mp11.hpp>`.

View File

@@ -37,4 +37,8 @@ include::integer_sequence.adoc[]
include::tuple.adoc[]
include::mp11.adoc[]
include::mpl.adoc[]
:leveloffset: -1

175
include/boost/mp11/mpl.hpp Normal file
View 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

View File

@@ -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
View 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();
}