From 29a771aa4eacc065af6bf133364621360cf56223 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 23 May 2017 20:24:37 +0300 Subject: [PATCH] Move integer_sequence and tuple_for_each into mp11 --- doc/html/mp11.html | 26 +++---- doc/mp11.qbk | 2 +- doc/mp11/examples.qbk | 3 +- doc/mp11/integer_sequence.qbk | 4 +- doc/mp11/tuple_for_each.qbk | 4 +- include/boost/mp11.hpp | 2 + include/boost/mp11/algorithm.hpp | 2 +- include/boost/{ => mp11}/integer_sequence.hpp | 16 ++++- include/boost/{ => mp11}/tuple_for_each.hpp | 22 ++++-- test/integer_sequence.cpp | 68 ++++++++++--------- test/tuple_for_each.cpp | 26 +++---- test/tuple_for_each_cx.cpp | 6 +- 12 files changed, 99 insertions(+), 82 deletions(-) rename include/boost/{ => mp11}/integer_sequence.hpp (84%) rename include/boost/{ => mp11}/tuple_for_each.hpp (57%) diff --git a/doc/html/mp11.html b/doc/html/mp11.html index 1e3acf2..d3e10e3 100644 --- a/doc/html/mp11.html +++ b/doc/html/mp11.html @@ -187,7 +187,7 @@
mp_bind_back_q<Q, T...>
Integer Sequences, - <boost/integer_sequence.hpp>
+ <boost/mp11/integer_sequence.hpp>
integer_sequence<T, I...>
make_integer_sequence<T, N>
@@ -196,7 +196,7 @@
index_sequence_for<T...>
A "for each" - algorithm for tuple-like types, <boost/tuple_for_each.hpp>
+ algorithm for tuple-like types, <boost/mp11/tuple_for_each.hpp>
tuple_for_each
@@ -341,7 +341,6 @@ worst of all, boring. This is 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>
@@ -369,7 +368,7 @@
 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); } );
 }
 

@@ -871,8 +870,7 @@ Reference

- The contents of the library are in namespace boost::mp11, unless - specified otherwise. + The contents of the library are in namespace boost::mp11.

@@ -2332,12 +2330,9 @@

-

- The contents of this header are defined in namespace boost. -

integer_sequence<T, I...> @@ -2401,12 +2396,9 @@

-

- The contents of this header are defined in namespace boost. -

tuple_for_each @@ -2429,7 +2421,7 @@

- +

Last revised: May 22, 2017 at 13:46:31 GMT

Last revised: May 23, 2017 at 17:21:43 GMT


diff --git a/doc/mp11.qbk b/doc/mp11.qbk index db40f52..51e6b83 100644 --- a/doc/mp11.qbk +++ b/doc/mp11.qbk @@ -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] diff --git a/doc/mp11/examples.qbk b/doc/mp11/examples.qbk index 93aad48..a54a458 100644 --- a/doc/mp11/examples.qbk +++ b/doc/mp11/examples.qbk @@ -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 - #include #include #include #include @@ -70,7 +69,7 @@ how we can leverage Mp11 to automate the task: int main() { using L = std::tuple; - boost::tuple_for_each( mp_product(), [](auto&& x){ test_result(x); } ); + tuple_for_each( mp_product(), [](auto&& x){ test_result(x); } ); } How does it work? diff --git a/doc/mp11/integer_sequence.qbk b/doc/mp11/integer_sequence.qbk index f0604b6..199634a 100644 --- a/doc/mp11/integer_sequence.qbk +++ b/doc/mp11/integer_sequence.qbk @@ -6,9 +6,7 @@ / http://www.boost.org/LICENSE_1_0.txt) /] -[section:integer_sequence Integer Sequences, ``] - -The contents of this header are defined in namespace `boost`. +[section:integer_sequence Integer Sequences, ``] [section `integer_sequence`] template struct integer_sequence diff --git a/doc/mp11/tuple_for_each.qbk b/doc/mp11/tuple_for_each.qbk index 2b06fcd..4eb6b9e 100644 --- a/doc/mp11/tuple_for_each.qbk +++ b/doc/mp11/tuple_for_each.qbk @@ -6,9 +6,7 @@ / http://www.boost.org/LICENSE_1_0.txt) /] -[section:tuple_for_each A "for each" algorithm for tuple-like types, ``] - -The contents of this header are defined in namespace `boost`. +[section:tuple_for_each A "for each" algorithm for tuple-like types, ``] [section `tuple_for_each`] template constexpr F tuple_for_each(Tp&& tp, F&& f); diff --git a/include/boost/mp11.hpp b/include/boost/mp11.hpp index 4241337..05a51ca 100644 --- a/include/boost/mp11.hpp +++ b/include/boost/mp11.hpp @@ -16,5 +16,7 @@ #include #include #include +#include +#include #endif // #ifndef BOOST_MP11_HPP_INCLUDED diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 1762502..9f0a6f7 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/boost/integer_sequence.hpp b/include/boost/mp11/integer_sequence.hpp similarity index 84% rename from include/boost/integer_sequence.hpp rename to include/boost/mp11/integer_sequence.hpp index 9ddfc99..08e3120 100644 --- a/include/boost/integer_sequence.hpp +++ b/include/boost/mp11/integer_sequence.hpp @@ -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 namespace boost { +namespace mp11 +{ // integer_sequence template struct integer_sequence @@ -82,6 +91,7 @@ template using make_index_sequence = make_integer_sequence using index_sequence_for = make_integer_sequence; +} // namespace mp11 } // namespace boost -#endif // #ifndef BOOST_INTEGER_SEQUENCE_HPP_INCLUDED +#endif // #ifndef BOOST_MP11_INTEGER_SEQUENCE_HPP_INCLUDED diff --git a/include/boost/tuple_for_each.hpp b/include/boost/mp11/tuple_for_each.hpp similarity index 57% rename from include/boost/tuple_for_each.hpp rename to include/boost/mp11/tuple_for_each.hpp index 8e3d766..a58098e 100644 --- a/include/boost/tuple_for_each.hpp +++ b/include/boost/mp11/tuple_for_each.hpp @@ -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 +// 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 #include #include #include @@ -11,11 +18,13 @@ namespace boost { +namespace mp11 +{ namespace detail { -template BOOST_CONSTEXPR F tuple_for_each_impl( Tp && tp, boost::integer_sequence, F && f ) +template BOOST_CONSTEXPR F tuple_for_each_impl( Tp && tp, integer_sequence, F && f ) { using A = int[sizeof...(J)]; return (void)A{ ((void)f(std::get(std::forward(tp))), 0)... }, std::forward(f); @@ -23,7 +32,7 @@ template BOOST_CONSTEXPR F tuple_for_each_i #if BOOST_WORKAROUND( BOOST_MSVC, <= 1800 ) -template BOOST_CONSTEXPR F tuple_for_each_impl( Tp && tp, boost::integer_sequence, F && f ) +template BOOST_CONSTEXPR F tuple_for_each_impl( Tp && tp, integer_sequence, F && f ) { return std::forward(f); } @@ -34,10 +43,11 @@ template BOOST_CONSTEXPR F tuple_for_each_impl( Tp && tp, boo template BOOST_CONSTEXPR F tuple_for_each( Tp && tp, F && f ) { - using seq = boost::make_index_sequence::type>::value>; + using seq = make_index_sequence::type>::value>; return detail::tuple_for_each_impl( std::forward(tp), seq(), std::forward(f) ); } +} // namespace mp11 } // namespace boost #endif // #ifndef BOOST_TUPLE_FOR_EACH_HPP_INCLUDED diff --git a/test/integer_sequence.cpp b/test/integer_sequence.cpp index 190b985..bc489ab 100644 --- a/test/integer_sequence.cpp +++ b/test/integer_sequence.cpp @@ -7,47 +7,53 @@ // http://www.boost.org/LICENSE_1_0.txt -#include +#include #include #include int main() { - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + 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::integer_sequence>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, integer_sequence>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, integer_sequence>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, integer_sequence>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::index_sequence<>>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::index_sequence<0>>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::index_sequence<0, 1>>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::index_sequence<0, 1, 2>>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::index_sequence<0, 1, 2, 3>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, integer_sequence>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, integer_sequence>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::index_sequence<>>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::index_sequence<0>>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::index_sequence<0, 1>>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::index_sequence<0, 1, 2>>)); - BOOST_TEST_TRAIT_TRUE((std::is_same, boost::index_sequence<0, 1, 2, 3>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, index_sequence<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, index_sequence<0>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, index_sequence<0, 1>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, index_sequence<0, 1, 2>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, index_sequence<0, 1, 2, 3>>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, index_sequence<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, index_sequence<0>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, index_sequence<0, 1>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, index_sequence<0, 1, 2>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, index_sequence<0, 1, 2, 3>>)); return boost::report_errors(); } diff --git a/test/tuple_for_each.cpp b/test/tuple_for_each.cpp index e8880dd..449fd15 100644 --- a/test/tuple_for_each.cpp +++ b/test/tuple_for_each.cpp @@ -7,7 +7,7 @@ // http://www.boost.org/LICENSE_1_0.txt -#include +#include #include #include #include @@ -16,13 +16,15 @@ int main() { + using boost::mp11::tuple_for_each; + { std::tuple 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 p ){ s = s * 10 + *p; } ); + tuple_for_each( std::move(tp), [&]( std::unique_ptr 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 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(); diff --git a/test/tuple_for_each_cx.cpp b/test/tuple_for_each_cx.cpp index 305d737..730f6d2 100644 --- a/test/tuple_for_each_cx.cpp +++ b/test/tuple_for_each_cx.cpp @@ -6,7 +6,7 @@ // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt -#include +#include #include // Technically std::tuple isn't constexpr enabled in C++11, but it works with libstdc++ @@ -33,7 +33,7 @@ int main() { { constexpr std::tuple 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" ); }