1
0
forked from boostorg/mp11

Move integer_sequence and tuple_for_each into mp11

This commit is contained in:
Peter Dimov
2017-05-23 20:24:37 +03:00
parent 6ebdd308e3
commit 29a771aa4e
12 changed files with 99 additions and 82 deletions

View File

@@ -187,7 +187,7 @@
<dt><span class="section"><a href="mp11.html#mp11.reference.bind.mp_bind_back_q_q_t"><code class="computeroutput"><span class="identifier">mp_bind_back_q</span><span class="special">&lt;</span><span class="identifier">Q</span><span class="special">,</span> <span class="identifier">T</span><span class="special">...&gt;</span></code></a></span></dt>
</dl></dd>
<dt><span class="section"><a href="mp11.html#mp11.reference.integer_sequence">Integer Sequences,
<code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer_sequence</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code></a></span></dt>
<code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">mp11</span><span class="special">/</span><span class="identifier">integer_sequence</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code></a></span></dt>
<dd><dl>
<dt><span class="section"><a href="mp11.html#mp11.reference.integer_sequence.integer_sequence_t_i"><code class="computeroutput"><span class="identifier">integer_sequence</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">I</span><span class="special">...&gt;</span></code></a></span></dt>
<dt><span class="section"><a href="mp11.html#mp11.reference.integer_sequence.make_integer_sequence_t_n"><code class="computeroutput"><span class="identifier">make_integer_sequence</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">N</span><span class="special">&gt;</span></code></a></span></dt>
@@ -196,7 +196,7 @@
<dt><span class="section"><a href="mp11.html#mp11.reference.integer_sequence.index_sequence_for_t"><code class="computeroutput"><span class="identifier">index_sequence_for</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">...&gt;</span></code></a></span></dt>
</dl></dd>
<dt><span class="section"><a href="mp11.html#mp11.reference.tuple_for_each">A "for each"
algorithm for tuple-like types, <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">tuple_for_each</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code></a></span></dt>
algorithm for tuple-like types, <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">mp11</span><span class="special">/</span><span class="identifier">tuple_for_each</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code></a></span></dt>
<dd><dl><dt><span class="section"><a href="mp11.html#mp11.reference.tuple_for_each.tuple_for_each"><code class="computeroutput"><span class="identifier">tuple_for_each</span></code></a></span></dt></dl></dd>
</dl></dd>
</dl>
@@ -341,7 +341,6 @@
worst of all, boring. This is how we can leverage Mp11 to automate the task:
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">mp11</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">tuple_for_each</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">core</span><span class="special">/</span><span class="identifier">demangle</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">type_traits</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
@@ -369,7 +368,7 @@
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
<span class="special">{</span>
<span class="keyword">using</span> <span class="identifier">L</span> <span class="special">=</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple</span><span class="special">&lt;</span><span class="keyword">char</span><span class="special">,</span> <span class="keyword">short</span><span class="special">,</span> <span class="keyword">int</span><span class="special">,</span> <span class="keyword">unsigned</span><span class="special">,</span> <span class="keyword">long</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">long</span><span class="special">&gt;;</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">tuple_for_each</span><span class="special">(</span> <span class="identifier">mp_product</span><span class="special">&lt;</span><span class="identifier">mp_list</span><span class="special">,</span> <span class="identifier">L</span><span class="special">,</span> <span class="identifier">L</span><span class="special">&gt;(),</span> <span class="special">[](</span><span class="keyword">auto</span><span class="special">&amp;&amp;</span> <span class="identifier">x</span><span class="special">){</span> <span class="identifier">test_result</span><span class="special">(</span><span class="identifier">x</span><span class="special">);</span> <span class="special">}</span> <span class="special">);</span>
<span class="identifier">tuple_for_each</span><span class="special">(</span> <span class="identifier">mp_product</span><span class="special">&lt;</span><span class="identifier">mp_list</span><span class="special">,</span> <span class="identifier">L</span><span class="special">,</span> <span class="identifier">L</span><span class="special">&gt;(),</span> <span class="special">[](</span><span class="keyword">auto</span><span class="special">&amp;&amp;</span> <span class="identifier">x</span><span class="special">){</span> <span class="identifier">test_result</span><span class="special">(</span><span class="identifier">x</span><span class="special">);</span> <span class="special">}</span> <span class="special">);</span>
<span class="special">}</span>
</pre>
<p>
@@ -871,8 +870,7 @@
<a name="mp11.reference"></a><a class="link" href="mp11.html#mp11.reference" title="Reference">Reference</a>
</h2></div></div></div>
<p>
The contents of the library are in namespace <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">mp11</span></code>, unless
specified otherwise.
The contents of the library are in namespace <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">mp11</span></code>.
</p>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
@@ -2332,12 +2330,9 @@
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="mp11.reference.integer_sequence"></a><a class="link" href="mp11.html#mp11.reference.integer_sequence" title="Integer Sequences, &lt;boost/integer_sequence.hpp&gt;">Integer Sequences,
<code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer_sequence</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code></a>
<a name="mp11.reference.integer_sequence"></a><a class="link" href="mp11.html#mp11.reference.integer_sequence" title="Integer Sequences, &lt;boost/mp11/integer_sequence.hpp&gt;">Integer Sequences,
<code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">mp11</span><span class="special">/</span><span class="identifier">integer_sequence</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code></a>
</h3></div></div></div>
<p>
The contents of this header are defined in namespace <code class="computeroutput"><span class="identifier">boost</span></code>.
</p>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="mp11.reference.integer_sequence.integer_sequence_t_i"></a><a class="link" href="mp11.html#mp11.reference.integer_sequence.integer_sequence_t_i" title="integer_sequence&lt;T, I...&gt;"><code class="computeroutput"><span class="identifier">integer_sequence</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">I</span><span class="special">...&gt;</span></code></a>
@@ -2401,12 +2396,9 @@
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="mp11.reference.tuple_for_each"></a><a class="link" href="mp11.html#mp11.reference.tuple_for_each" title='A "for each" algorithm for tuple-like types, &lt;boost/tuple_for_each.hpp&gt;'>A "for each"
algorithm for tuple-like types, <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">tuple_for_each</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code></a>
<a name="mp11.reference.tuple_for_each"></a><a class="link" href="mp11.html#mp11.reference.tuple_for_each" title='A "for each" algorithm for tuple-like types, &lt;boost/mp11/tuple_for_each.hpp&gt;'>A "for each"
algorithm for tuple-like types, <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">mp11</span><span class="special">/</span><span class="identifier">tuple_for_each</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code></a>
</h3></div></div></div>
<p>
The contents of this header are defined in namespace <code class="computeroutput"><span class="identifier">boost</span></code>.
</p>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="mp11.reference.tuple_for_each.tuple_for_each"></a><a class="link" href="mp11.html#mp11.reference.tuple_for_each.tuple_for_each" title="tuple_for_each"><code class="computeroutput"><span class="identifier">tuple_for_each</span></code></a>
@@ -2429,7 +2421,7 @@
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"><p><small>Last revised: May 22, 2017 at 13:46:31 GMT</small></p></td>
<td align="left"><p><small>Last revised: May 23, 2017 at 17:21:43 GMT</small></p></td>
<td align="right"><div class="copyright-footer"></div></td>
</tr></table>
<hr>

View File

@@ -29,7 +29,7 @@
[section Reference]
The contents of the library are in namespace `boost::mp11`, unless specified otherwise.
The contents of the library are in namespace `boost::mp11`.
[include mp11/integral.qbk]
[include mp11/list.qbk]

View File

@@ -42,7 +42,6 @@ Writing all those type combinations by hand is unwieldy, error prone, and worst
how we can leverage Mp11 to automate the task:
#include <boost/mp11.hpp>
#include <boost/tuple_for_each.hpp>
#include <boost/core/demangle.hpp>
#include <type_traits>
#include <iostream>
@@ -70,7 +69,7 @@ how we can leverage Mp11 to automate the task:
int main()
{
using L = std::tuple<char, short, int, unsigned, long, unsigned long>;
boost::tuple_for_each( mp_product<mp_list, L, L>(), [](auto&& x){ test_result(x); } );
tuple_for_each( mp_product<mp_list, L, L>(), [](auto&& x){ test_result(x); } );
}
How does it work?

View File

@@ -6,9 +6,7 @@
/ http://www.boost.org/LICENSE_1_0.txt)
/]
[section:integer_sequence Integer Sequences, `<boost/integer_sequence.hpp>`]
The contents of this header are defined in namespace `boost`.
[section:integer_sequence Integer Sequences, `<boost/mp11/integer_sequence.hpp>`]
[section `integer_sequence<T, I...>`]
template<class T, T... I> struct integer_sequence

View File

@@ -6,9 +6,7 @@
/ http://www.boost.org/LICENSE_1_0.txt)
/]
[section:tuple_for_each A "for each" algorithm for tuple-like types, `<boost/tuple_for_each.hpp>`]
The contents of this header are defined in namespace `boost`.
[section:tuple_for_each A "for each" algorithm for tuple-like types, `<boost/mp11/tuple_for_each.hpp>`]
[section `tuple_for_each`]
template<class Tp, class F> constexpr F tuple_for_each(Tp&& tp, F&& f);

View File

@@ -16,5 +16,7 @@
#include <boost/mp11/map.hpp>
#include <boost/mp11/set.hpp>
#include <boost/mp11/bind.hpp>
#include <boost/mp11/integer_sequence.hpp>
#include <boost/mp11/tuple_for_each.hpp>
#endif // #ifndef BOOST_MP11_HPP_INCLUDED

View File

@@ -17,7 +17,7 @@
#include <boost/mp11/detail/mp_plus.hpp>
#include <boost/mp11/detail/mp_map_find.hpp>
#include <boost/mp11/detail/config.hpp>
#include <boost/integer_sequence.hpp>
#include <boost/mp11/integer_sequence.hpp>
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
#include <type_traits>

View File

@@ -1,10 +1,19 @@
#ifndef BOOST_INTEGER_SEQUENCE_HPP_INCLUDED
#define BOOST_INTEGER_SEQUENCE_HPP_INCLUDED
#ifndef BOOST_MP11_INTEGER_SEQUENCE_HPP_INCLUDED
#define BOOST_MP11_INTEGER_SEQUENCE_HPP_INCLUDED
// Copyright 2015, 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 <cstddef>
namespace boost
{
namespace mp11
{
// integer_sequence
template<class T, T... I> struct integer_sequence
@@ -82,6 +91,7 @@ template<std::size_t N> using make_index_sequence = make_integer_sequence<std::s
// index_sequence_for
template<class... T> using index_sequence_for = make_integer_sequence<std::size_t, sizeof...(T)>;
} // namespace mp11
} // namespace boost
#endif // #ifndef BOOST_INTEGER_SEQUENCE_HPP_INCLUDED
#endif // #ifndef BOOST_MP11_INTEGER_SEQUENCE_HPP_INCLUDED

View File

@@ -1,7 +1,14 @@
#ifndef BOOST_TUPLE_FOR_EACH_HPP_INCLUDED
#define BOOST_TUPLE_FOR_EACH_HPP_INCLUDED
#ifndef BOOST_MP11_TUPLE_FOR_EACH_HPP_INCLUDED
#define BOOST_MP11_TUPLE_FOR_EACH_HPP_INCLUDED
#include <boost/integer_sequence.hpp>
// Copyright 2015, 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/integer_sequence.hpp>
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
#include <tuple>
@@ -11,11 +18,13 @@
namespace boost
{
namespace mp11
{
namespace detail
{
template<class Tp, std::size_t... J, class F> BOOST_CONSTEXPR F tuple_for_each_impl( Tp && tp, boost::integer_sequence<std::size_t, J...>, F && f )
template<class Tp, std::size_t... J, class F> BOOST_CONSTEXPR F tuple_for_each_impl( Tp && tp, integer_sequence<std::size_t, J...>, F && f )
{
using A = int[sizeof...(J)];
return (void)A{ ((void)f(std::get<J>(std::forward<Tp>(tp))), 0)... }, std::forward<F>(f);
@@ -23,7 +32,7 @@ template<class Tp, std::size_t... J, class F> BOOST_CONSTEXPR F tuple_for_each_i
#if BOOST_WORKAROUND( BOOST_MSVC, <= 1800 )
template<class Tp, class F> BOOST_CONSTEXPR F tuple_for_each_impl( Tp && tp, boost::integer_sequence<std::size_t>, F && f )
template<class Tp, class F> BOOST_CONSTEXPR F tuple_for_each_impl( Tp && tp, integer_sequence<std::size_t>, F && f )
{
return std::forward<F>(f);
}
@@ -34,10 +43,11 @@ template<class Tp, class F> BOOST_CONSTEXPR F tuple_for_each_impl( Tp && tp, boo
template<class Tp, class F> BOOST_CONSTEXPR F tuple_for_each( Tp && tp, F && f )
{
using seq = boost::make_index_sequence<std::tuple_size<typename std::remove_reference<Tp>::type>::value>;
using seq = make_index_sequence<std::tuple_size<typename std::remove_reference<Tp>::type>::value>;
return detail::tuple_for_each_impl( std::forward<Tp>(tp), seq(), std::forward<F>(f) );
}
} // namespace mp11
} // namespace boost
#endif // #ifndef BOOST_TUPLE_FOR_EACH_HPP_INCLUDED

View File

@@ -7,47 +7,53 @@
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/integer_sequence.hpp>
#include <boost/mp11/integer_sequence.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <type_traits>
int main()
{
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_integer_sequence<int, 0>, boost::integer_sequence<int>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_integer_sequence<int, 1>, boost::integer_sequence<int, 0>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_integer_sequence<int, 2>, boost::integer_sequence<int, 0, 1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_integer_sequence<int, 3>, boost::integer_sequence<int, 0, 1, 2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_integer_sequence<int, 4>, boost::integer_sequence<int, 0, 1, 2, 3>>));
using boost::mp11::integer_sequence;
using boost::mp11::make_integer_sequence;
using boost::mp11::index_sequence;
using boost::mp11::make_index_sequence;
using boost::mp11::index_sequence_for;
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_integer_sequence<char, 0>, boost::integer_sequence<char>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_integer_sequence<char, 1>, boost::integer_sequence<char, 0>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_integer_sequence<char, 2>, boost::integer_sequence<char, 0, 1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_integer_sequence<char, 3>, boost::integer_sequence<char, 0, 1, 2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_integer_sequence<char, 4>, boost::integer_sequence<char, 0, 1, 2, 3>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_integer_sequence<int, 0>, integer_sequence<int>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_integer_sequence<int, 1>, integer_sequence<int, 0>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_integer_sequence<int, 2>, integer_sequence<int, 0, 1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_integer_sequence<int, 3>, integer_sequence<int, 0, 1, 2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_integer_sequence<int, 4>, integer_sequence<int, 0, 1, 2, 3>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_integer_sequence<std::size_t, 0>, boost::integer_sequence<std::size_t>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_integer_sequence<std::size_t, 1>, boost::integer_sequence<std::size_t, 0>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_integer_sequence<std::size_t, 2>, boost::integer_sequence<std::size_t, 0, 1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_integer_sequence<std::size_t, 3>, boost::integer_sequence<std::size_t, 0, 1, 2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_integer_sequence<std::size_t, 4>, boost::integer_sequence<std::size_t, 0, 1, 2, 3>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_integer_sequence<char, 0>, integer_sequence<char>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_integer_sequence<char, 1>, integer_sequence<char, 0>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_integer_sequence<char, 2>, integer_sequence<char, 0, 1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_integer_sequence<char, 3>, integer_sequence<char, 0, 1, 2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_integer_sequence<char, 4>, integer_sequence<char, 0, 1, 2, 3>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_index_sequence<0>, boost::integer_sequence<std::size_t>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_index_sequence<1>, boost::integer_sequence<std::size_t, 0>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_index_sequence<2>, boost::integer_sequence<std::size_t, 0, 1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_index_sequence<3>, boost::integer_sequence<std::size_t, 0, 1, 2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_index_sequence<4>, boost::integer_sequence<std::size_t, 0, 1, 2, 3>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_integer_sequence<std::size_t, 0>, integer_sequence<std::size_t>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_integer_sequence<std::size_t, 1>, integer_sequence<std::size_t, 0>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_integer_sequence<std::size_t, 2>, integer_sequence<std::size_t, 0, 1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_integer_sequence<std::size_t, 3>, integer_sequence<std::size_t, 0, 1, 2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_integer_sequence<std::size_t, 4>, integer_sequence<std::size_t, 0, 1, 2, 3>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_index_sequence<0>, boost::index_sequence<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_index_sequence<1>, boost::index_sequence<0>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_index_sequence<2>, boost::index_sequence<0, 1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_index_sequence<3>, boost::index_sequence<0, 1, 2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::make_index_sequence<4>, boost::index_sequence<0, 1, 2, 3>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_index_sequence<0>, integer_sequence<std::size_t>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_index_sequence<1>, integer_sequence<std::size_t, 0>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_index_sequence<2>, integer_sequence<std::size_t, 0, 1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_index_sequence<3>, integer_sequence<std::size_t, 0, 1, 2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_index_sequence<4>, integer_sequence<std::size_t, 0, 1, 2, 3>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::index_sequence_for<>, boost::index_sequence<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::index_sequence_for<void>, boost::index_sequence<0>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::index_sequence_for<void, void>, boost::index_sequence<0, 1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::index_sequence_for<void, void, void>, boost::index_sequence<0, 1, 2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<boost::index_sequence_for<void, void, void, void>, boost::index_sequence<0, 1, 2, 3>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_index_sequence<0>, index_sequence<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_index_sequence<1>, index_sequence<0>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_index_sequence<2>, index_sequence<0, 1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_index_sequence<3>, index_sequence<0, 1, 2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<make_index_sequence<4>, index_sequence<0, 1, 2, 3>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<index_sequence_for<>, index_sequence<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<index_sequence_for<void>, index_sequence<0>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<index_sequence_for<void, void>, index_sequence<0, 1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<index_sequence_for<void, void, void>, index_sequence<0, 1, 2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<index_sequence_for<void, void, void, void>, index_sequence<0, 1, 2, 3>>));
return boost::report_errors();
}

View File

@@ -7,7 +7,7 @@
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/tuple_for_each.hpp>
#include <boost/mp11/tuple_for_each.hpp>
#include <boost/core/lightweight_test.hpp>
#include <tuple>
#include <memory>
@@ -16,13 +16,15 @@
int main()
{
using boost::mp11::tuple_for_each;
{
std::tuple<int, short, char> tp{ 1, 2, 3 };
{
int s = 0;
boost::tuple_for_each( tp, [&]( int x ){ s = s * 10 + x; } );
tuple_for_each( tp, [&]( int x ){ s = s * 10 + x; } );
BOOST_TEST_EQ( s, 123 );
}
@@ -30,7 +32,7 @@ int main()
{
int s = 0;
boost::tuple_for_each( std::move(tp), [&]( int x ){ s = s * 10 + x; } );
tuple_for_each( std::move(tp), [&]( int x ){ s = s * 10 + x; } );
BOOST_TEST_EQ( s, 123 );
}
@@ -44,7 +46,7 @@ int main()
int s = 0;
boost::tuple_for_each( std::move(tp), [&]( std::unique_ptr<int> p ){ s = s * 10 + *p; } );
tuple_for_each( std::move(tp), [&]( std::unique_ptr<int> p ){ s = s * 10 + *p; } );
BOOST_TEST_EQ( s, 123 );
}
@@ -57,7 +59,7 @@ int main()
{
int s = 0;
boost::tuple_for_each( tp, [&]( int x ){ s = s * 10 + x; } );
tuple_for_each( tp, [&]( int x ){ s = s * 10 + x; } );
BOOST_TEST_EQ( s, 12 );
}
@@ -65,7 +67,7 @@ int main()
{
int s = 0;
boost::tuple_for_each( std::move(tp), [&]( int x ){ s = s * 10 + x; } );
tuple_for_each( std::move(tp), [&]( int x ){ s = s * 10 + x; } );
BOOST_TEST_EQ( s, 12 );
}
@@ -77,7 +79,7 @@ int main()
{
int s = 0;
boost::tuple_for_each( tp, [&]( int x ){ s = s * 10 + x; } );
tuple_for_each( tp, [&]( int x ){ s = s * 10 + x; } );
BOOST_TEST_EQ( s, 123 );
}
@@ -85,7 +87,7 @@ int main()
{
int s = 0;
boost::tuple_for_each( std::move(tp), [&]( int x ){ s = s * 10 + x; } );
tuple_for_each( std::move(tp), [&]( int x ){ s = s * 10 + x; } );
BOOST_TEST_EQ( s, 123 );
}
@@ -94,15 +96,15 @@ int main()
{
std::tuple<> tp;
BOOST_TEST_EQ( boost::tuple_for_each( tp, 11 ), 11 );
BOOST_TEST_EQ( boost::tuple_for_each( std::move( tp ), 12 ), 12 );
BOOST_TEST_EQ( tuple_for_each( tp, 11 ), 11 );
BOOST_TEST_EQ( tuple_for_each( std::move( tp ), 12 ), 12 );
}
{
std::array<int, 0> tp;
BOOST_TEST_EQ( boost::tuple_for_each( tp, 11 ), 11 );
BOOST_TEST_EQ( boost::tuple_for_each( std::move( tp ), 12 ), 12 );
BOOST_TEST_EQ( tuple_for_each( tp, 11 ), 11 );
BOOST_TEST_EQ( tuple_for_each( std::move( tp ), 12 ), 12 );
}
return boost::report_errors();

View File

@@ -6,7 +6,7 @@
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/tuple_for_each.hpp>
#include <boost/mp11/tuple_for_each.hpp>
#include <boost/config.hpp>
// Technically std::tuple isn't constexpr enabled in C++11, but it works with libstdc++
@@ -33,7 +33,7 @@ int main()
{
{
constexpr std::tuple<int, short, char> tp{ 1, 2, 3 };
constexpr auto r = boost::tuple_for_each( tp, assert_is_integral() );
constexpr auto r = boost::mp11::tuple_for_each( tp, assert_is_integral() );
(void)r;
}
@@ -42,7 +42,7 @@ int main()
{
constexpr std::tuple<> tp;
constexpr auto r = boost::tuple_for_each( tp, 11 );
constexpr auto r = boost::mp11::tuple_for_each( tp, 11 );
static_assert( r == 11, "r == 11" );
}