Skip to content

Commit

Permalink
Rename right_folds::variadic to right_folds::variadic_unrolled.
Browse files Browse the repository at this point in the history
  • Loading branch information
ldionne committed May 5, 2014
1 parent 843ac2f commit 7923ad2
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 91 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @file
* Defines `boost::mpl11::detail::right_folds::variadic`.
* Defines `boost::mpl11::detail::right_folds::variadic_unrolled`.
*
*
* @copyright Louis Dionne 2014
Expand All @@ -13,8 +13,8 @@
// GENERATED HEADER: DO NOT EDIT.
//////////////////////////////////////////////////////////////////////////

#ifndef BOOST_MPL11_DETAIL_RIGHT_FOLDS_VARIADIC_HPP
#define BOOST_MPL11_DETAIL_RIGHT_FOLDS_VARIADIC_HPP
#ifndef BOOST_MPL11_DETAIL_RIGHT_FOLDS_VARIADIC_UNROLLED_HPP
#define BOOST_MPL11_DETAIL_RIGHT_FOLDS_VARIADIC_UNROLLED_HPP

namespace boost { namespace mpl11 { namespace detail { namespace right_folds {
<%
Expand All @@ -29,22 +29,22 @@ namespace boost { namespace mpl11 { namespace detail { namespace right_folds {
/*!
* @ingroup details
*
* Right fold over a parameter pack.
* Right fold over a parameter pack with loop unrolling.
*
* The metafunction is unlifted for performance.
*/
template <template <typename ...> class f, typename state, typename ...xs>
struct variadic;
struct variadic_unrolled;

template <
template <typename ...> class f,
typename state
<%= comma(typename(xs(0..unroll))).join %>,
typename ...xs>
struct variadic<f, state <%= comma(xs(0..unroll)).join %>, xs...>
struct variadic_unrolled<f, state <%= comma(xs(0..unroll)).join %>, xs...>
: <%=
xs(0..unroll).foldr("variadic<f, state, xs...>", &f)
.sub(/^typename/, "")
xs(0..unroll).foldr("variadic_unrolled<f, state, xs...>", &f)
.sub(/^typename/, '')
%>
{ };

Expand All @@ -54,10 +54,10 @@ namespace boost { namespace mpl11 { namespace detail { namespace right_folds {
typename state
<%= comma(typename(xs(0...n))).join %>
>
struct variadic<f, state <%= comma(xs(0...n)).join %> >
: <%= xs(0...n).foldr("state", &f).sub(/^typename/, "") %>
struct variadic_unrolled<f, state <%= comma(xs(0...n)).join %> >
: <%= xs(0...n).foldr("state", &f).sub(/^typename/, '') %>
{ };
<% end %>
}}}} // end namespace boost::mpl11::detail::right_folds

#endif // !BOOST_MPL11_DETAIL_RIGHT_FOLDS_VARIADIC_HPP
#endif // !BOOST_MPL11_DETAIL_RIGHT_FOLDS_VARIADIC_UNROLLED_HPP
80 changes: 5 additions & 75 deletions include/boost/mpl11/detail/right_folds/variadic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,90 +9,20 @@
* http://www.boost.org/LICENSE_1_0.txt)
*/

//////////////////////////////////////////////////////////////////////////
// GENERATED HEADER: DO NOT EDIT.
//////////////////////////////////////////////////////////////////////////

#ifndef BOOST_MPL11_DETAIL_RIGHT_FOLDS_VARIADIC_HPP
#define BOOST_MPL11_DETAIL_RIGHT_FOLDS_VARIADIC_HPP

namespace boost { namespace mpl11 { namespace detail { namespace right_folds {

#include <boost/mpl11/detail/right_folds/variadic_unrolled.hpp>


namespace boost { namespace mpl11 { namespace detail { namespace right_folds {
/*!
* @ingroup details
*
* Right fold over a parameter pack.
*
* The metafunction is unlifted for performance.
* Alias to the most efficient variadic right fold.
*/
template <template <typename ...> class f, typename state, typename ...xs>
struct variadic;

template <
template <typename ...> class f,
typename state
, typename x0, typename x1, typename x2, typename x3, typename x4, typename x5,
typename ...xs>
struct variadic<f, state , x0, x1, x2, x3, x4, x5, xs...>
: f<x0, f<x1, f<x2, f<x3, f<x4, f<x5, variadic<f, state, xs...>>>>>>>
{ };


template <
template <typename ...> class f,
typename state

>
struct variadic<f, state >
: state
{ };

template <
template <typename ...> class f,
typename state
, typename x0
>
struct variadic<f, state , x0 >
: f<x0, state>
{ };

template <
template <typename ...> class f,
typename state
, typename x0, typename x1
>
struct variadic<f, state , x0, x1 >
: f<x0, f<x1, state>>
{ };

template <
template <typename ...> class f,
typename state
, typename x0, typename x1, typename x2
>
struct variadic<f, state , x0, x1, x2 >
: f<x0, f<x1, f<x2, state>>>
{ };

template <
template <typename ...> class f,
typename state
, typename x0, typename x1, typename x2, typename x3
>
struct variadic<f, state , x0, x1, x2, x3 >
: f<x0, f<x1, f<x2, f<x3, state>>>>
{ };

template <
template <typename ...> class f,
typename state
, typename x0, typename x1, typename x2, typename x3, typename x4
>
struct variadic<f, state , x0, x1, x2, x3, x4 >
: f<x0, f<x1, f<x2, f<x3, f<x4, state>>>>>
{ };

using variadic = variadic_unrolled<f, state, xs...>;
}}}} // end namespace boost::mpl11::detail::right_folds

#endif // !BOOST_MPL11_DETAIL_RIGHT_FOLDS_VARIADIC_HPP
98 changes: 98 additions & 0 deletions include/boost/mpl11/detail/right_folds/variadic_unrolled.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*!
* @file
* Defines `boost::mpl11::detail::right_folds::variadic_unrolled`.
*
*
* @copyright Louis Dionne 2014
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE.md or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/

//////////////////////////////////////////////////////////////////////////
// GENERATED HEADER: DO NOT EDIT.
//////////////////////////////////////////////////////////////////////////

#ifndef BOOST_MPL11_DETAIL_RIGHT_FOLDS_VARIADIC_UNROLLED_HPP
#define BOOST_MPL11_DETAIL_RIGHT_FOLDS_VARIADIC_UNROLLED_HPP

namespace boost { namespace mpl11 { namespace detail { namespace right_folds {


/*!
* @ingroup details
*
* Right fold over a parameter pack with loop unrolling.
*
* The metafunction is unlifted for performance.
*/
template <template <typename ...> class f, typename state, typename ...xs>
struct variadic_unrolled;

template <
template <typename ...> class f,
typename state
, typename x0, typename x1, typename x2, typename x3, typename x4, typename x5,
typename ...xs>
struct variadic_unrolled<f, state , x0, x1, x2, x3, x4, x5, xs...>
: f<x0, f<x1, f<x2, f<x3, f<x4, f<x5, variadic_unrolled<f, state, xs...>>>>>>>
{ };


template <
template <typename ...> class f,
typename state

>
struct variadic_unrolled<f, state >
: state
{ };

template <
template <typename ...> class f,
typename state
, typename x0
>
struct variadic_unrolled<f, state , x0 >
: f<x0, state>
{ };

template <
template <typename ...> class f,
typename state
, typename x0, typename x1
>
struct variadic_unrolled<f, state , x0, x1 >
: f<x0, f<x1, state>>
{ };

template <
template <typename ...> class f,
typename state
, typename x0, typename x1, typename x2
>
struct variadic_unrolled<f, state , x0, x1, x2 >
: f<x0, f<x1, f<x2, state>>>
{ };

template <
template <typename ...> class f,
typename state
, typename x0, typename x1, typename x2, typename x3
>
struct variadic_unrolled<f, state , x0, x1, x2, x3 >
: f<x0, f<x1, f<x2, f<x3, state>>>>
{ };

template <
template <typename ...> class f,
typename state
, typename x0, typename x1, typename x2, typename x3, typename x4
>
struct variadic_unrolled<f, state , x0, x1, x2, x3, x4 >
: f<x0, f<x1, f<x2, f<x3, f<x4, state>>>>>
{ };

}}}} // end namespace boost::mpl11::detail::right_folds

#endif // !BOOST_MPL11_DETAIL_RIGHT_FOLDS_VARIADIC_UNROLLED_HPP
10 changes: 5 additions & 5 deletions test/detail/right_folds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* http://www.boost.org/LICENSE_1_0.txt)
*/

#include <boost/mpl11/detail/right_folds/variadic.hpp>
#include <boost/mpl11/detail/right_folds/variadic_naive.hpp>
#include <boost/mpl11/detail/right_folds/variadic_unrolled.hpp>

#include <boost/mpl11/detail/test/foldr.hpp>
#include <boost/mpl11/list.hpp>
Expand All @@ -19,19 +19,19 @@
using namespace boost::mpl11;

template <typename f, typename z, typename ...xs>
using variadic = detail::right_folds::variadic<
using variadic_naive = detail::right_folds::variadic_naive<
f::type::template apply, z, xs...
>;

template <typename f, typename z, typename ...xs>
using variadic_naive = detail::right_folds::variadic_naive<
using variadic_unrolled = detail::right_folds::variadic_unrolled<
f::type::template apply, z, xs...
>;


struct tests
: detail::test_foldr<variadic>
, detail::test_foldr<variadic_naive>
: detail::test_foldr<variadic_naive>
, detail::test_foldr<variadic_unrolled>
{ };


Expand Down

0 comments on commit 7923ad2

Please sign in to comment.