Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:43:52

0001 /*=============================================================================
0002     Copyright (c) 2015 Paul Fultz II
0003     rotate.h
0004     Distributed under the Boost Software License, Version 1.0. (See accompanying
0005     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 ==============================================================================*/
0007 
0008 #ifndef BOOST_HOF_GUARD_ROTATE_H
0009 #define BOOST_HOF_GUARD_ROTATE_H
0010 
0011 /// rotate
0012 /// ====
0013 /// 
0014 /// Description
0015 /// -----------
0016 /// 
0017 /// The `rotate` function adaptor moves the first parameter to the last
0018 /// parameter.
0019 /// 
0020 /// Synopsis
0021 /// --------
0022 /// 
0023 ///     template<class F>
0024 ///     rotate_adaptor<F> rotate(F f);
0025 /// 
0026 /// Semantics
0027 /// ---------
0028 /// 
0029 ///     assert(rotate(f)(x, xs...) == f(xs..., x));
0030 /// 
0031 /// Requirements
0032 /// ------------
0033 /// 
0034 /// F must be:
0035 /// 
0036 /// * [ConstInvocable](ConstInvocable)
0037 /// * MoveConstructible
0038 /// 
0039 /// Example
0040 /// -------
0041 /// 
0042 ///     #include <boost/hof.hpp>
0043 ///     #include <cassert>
0044 /// 
0045 ///     int main() {
0046 ///         int r = boost::hof::rotate(boost::hof::_ - boost::hof::_)(2, 5);
0047 ///         assert(r == 3);
0048 ///     }
0049 /// 
0050 
0051 #include <boost/hof/detail/result_of.hpp>
0052 #include <boost/hof/reveal.hpp>
0053 #include <boost/hof/detail/make.hpp>
0054 #include <boost/hof/detail/static_const_var.hpp>
0055 
0056 namespace boost { namespace hof {
0057 
0058 template<class F>
0059 struct rotate_adaptor : detail::callable_base<F>
0060 {
0061     typedef rotate_adaptor fit_rewritable1_tag;
0062     BOOST_HOF_INHERIT_CONSTRUCTOR(rotate_adaptor, detail::callable_base<F>);
0063 
0064     template<class... Ts>
0065     constexpr const detail::callable_base<F>& base_function(Ts&&... xs) const noexcept
0066     {
0067         return boost::hof::always_ref(*this)(xs...);
0068     }
0069 
0070     struct rotate_failure
0071     {
0072         template<class Failure>
0073         struct apply
0074         {
0075             template<class T, class... Ts>
0076             struct of
0077             : Failure::template of<Ts..., T>
0078             {};
0079         };
0080     };
0081 
0082     struct failure
0083     : failure_map<rotate_failure, detail::callable_base<F>>
0084     {};
0085 
0086     BOOST_HOF_RETURNS_CLASS(rotate_adaptor);
0087 
0088     template<class T, class... Ts>
0089     constexpr BOOST_HOF_SFINAE_RESULT(const detail::callable_base<F>&, id_<Ts>..., id_<T>) 
0090     operator()(T&& x, Ts&&... xs) const BOOST_HOF_SFINAE_RETURNS
0091     (
0092         (BOOST_HOF_MANGLE_CAST(const detail::callable_base<F>&)(BOOST_HOF_CONST_THIS->base_function(xs...)))
0093             (BOOST_HOF_FORWARD(Ts)(xs)..., BOOST_HOF_FORWARD(T)(x))
0094     );
0095 };
0096 
0097 BOOST_HOF_DECLARE_STATIC_VAR(rotate, detail::make<rotate_adaptor>);
0098 
0099 }} // namespace boost::hof
0100 
0101 #endif