1 /*=============================================================================
2 Copyright (c) 2015 Paul Fultz II
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
8 #ifndef BOOST_HOF_GUARD_ROTATE_H
9 #define BOOST_HOF_GUARD_ROTATE_H
17 /// The `rotate` function adaptor moves the first parameter to the last
24 /// rotate_adaptor<F> rotate(F f);
29 /// assert(rotate(f)(x, xs...) == f(xs..., x));
36 /// * [ConstInvocable](ConstInvocable)
37 /// * MoveConstructible
42 /// #include <boost/hof.hpp>
43 /// #include <cassert>
46 /// int r = boost::hof::rotate(boost::hof::_ - boost::hof::_)(2, 5);
51 #include <boost/hof/detail/result_of.hpp>
52 #include <boost/hof/reveal.hpp>
53 #include <boost/hof/detail/make.hpp>
54 #include <boost/hof/detail/static_const_var.hpp>
56 namespace boost { namespace hof {
59 struct rotate_adaptor : detail::callable_base<F>
61 typedef rotate_adaptor fit_rewritable1_tag;
62 BOOST_HOF_INHERIT_CONSTRUCTOR(rotate_adaptor, detail::callable_base<F>);
65 constexpr const detail::callable_base<F>& base_function(Ts&&... xs) const noexcept
67 return boost::hof::always_ref(*this)(xs...);
72 template<class Failure>
75 template<class T, class... Ts>
77 : Failure::template of<Ts..., T>
83 : failure_map<rotate_failure, detail::callable_base<F>>
86 BOOST_HOF_RETURNS_CLASS(rotate_adaptor);
88 template<class T, class... Ts>
89 constexpr BOOST_HOF_SFINAE_RESULT(const detail::callable_base<F>&, id_<Ts>..., id_<T>)
90 operator()(T&& x, Ts&&... xs) const BOOST_HOF_SFINAE_RETURNS
92 (BOOST_HOF_MANGLE_CAST(const detail::callable_base<F>&)(BOOST_HOF_CONST_THIS->base_function(xs...)))
93 (BOOST_HOF_FORWARD(Ts)(xs)..., BOOST_HOF_FORWARD(T)(x))
97 BOOST_HOF_DECLARE_STATIC_VAR(rotate, detail::make<rotate_adaptor>);
99 }} // namespace boost::hof