Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:15

0001 /*=============================================================================
0002     Copyright (c) 2015 Paul Fultz II
0003     flip.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_FLIP_H
0009 #define BOOST_HOF_GUARD_FLIP_H
0010 
0011 /// flip
0012 /// ====
0013 /// 
0014 /// Description
0015 /// -----------
0016 /// 
0017 /// The `flip` function adaptor swaps the first two parameters.
0018 /// 
0019 /// Synopsis
0020 /// --------
0021 /// 
0022 ///     template<class F>
0023 ///     flip_adaptor<F> flip(F f);
0024 /// 
0025 /// Semantics
0026 /// ---------
0027 /// 
0028 ///     assert(flip(f)(x, y, xs...) == f(y, x, xs...));
0029 /// 
0030 /// Requirements
0031 /// ------------
0032 /// 
0033 /// F must be at least:
0034 /// 
0035 /// * [BinaryInvocable](BinaryInvocable)
0036 /// 
0037 /// Or:
0038 /// 
0039 /// * [Invocable](Invocable) with more than two argurments
0040 /// 
0041 /// And:
0042 /// 
0043 /// * MoveConstructible
0044 /// 
0045 /// Example
0046 /// -------
0047 /// 
0048 ///     #include <boost/hof.hpp>
0049 ///     #include <cassert>
0050 /// 
0051 ///     int main() {
0052 ///         int r = boost::hof::flip(boost::hof::_ - boost::hof::_)(2, 5);
0053 ///         assert(r == 3);
0054 ///     }
0055 /// 
0056 
0057 #include <boost/hof/detail/callable_base.hpp>
0058 #include <boost/hof/reveal.hpp>
0059 #include <boost/hof/detail/make.hpp>
0060 #include <boost/hof/detail/static_const_var.hpp>
0061 
0062 namespace boost { namespace hof {
0063 
0064 template<class F>
0065 struct flip_adaptor : detail::callable_base<F>
0066 {
0067     typedef flip_adaptor fit_rewritable1_tag;
0068     BOOST_HOF_INHERIT_CONSTRUCTOR(flip_adaptor, detail::callable_base<F>);
0069 
0070     template<class... Ts>
0071     constexpr const detail::callable_base<F>& base_function(Ts&&... xs) const
0072     {
0073         return boost::hof::always_ref(*this)(xs...);
0074     }
0075 
0076     struct flip_failure
0077     {
0078         template<class Failure>
0079         struct apply
0080         {
0081             template<class T, class U, class... Ts>
0082             struct of
0083             : Failure::template of<U, T, Ts...>
0084             {};
0085         };
0086     };
0087 
0088     struct failure
0089     : failure_map<flip_failure, detail::callable_base<F>>
0090     {};
0091 
0092     BOOST_HOF_RETURNS_CLASS(flip_adaptor);
0093 
0094     template<class T, class U, class... Ts>
0095     constexpr BOOST_HOF_SFINAE_RESULT(const detail::callable_base<F>&, id_<U>, id_<T>, id_<Ts>...) 
0096     operator()(T&& x, U&& y, Ts&&... xs) const BOOST_HOF_SFINAE_RETURNS
0097     (
0098         (BOOST_HOF_MANGLE_CAST(const detail::callable_base<F>&)(BOOST_HOF_CONST_THIS->base_function(xs...)))
0099             (BOOST_HOF_FORWARD(U)(y), BOOST_HOF_FORWARD(T)(x), BOOST_HOF_FORWARD(Ts)(xs)...)
0100     );
0101 };
0102 
0103 BOOST_HOF_DECLARE_STATIC_VAR(flip, detail::make<flip_adaptor>);
0104 
0105 }} // namespace boost::hof
0106 
0107 #endif