3 Defines `boost::hana::flip`.
5 @copyright Louis Dionne 2013-2017
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_HANA_FUNCTIONAL_FLIP_HPP
11 #define BOOST_HANA_FUNCTIONAL_FLIP_HPP
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/detail/create.hpp>
19 BOOST_HANA_NAMESPACE_BEGIN
20 //! @ingroup group-functional
21 //! Invoke a function with its two first arguments reversed.
23 //! Specifically, `flip(f)` is a function such that
25 //! flip(f)(x, y, z...) == f(y, x, z...)
29 //! @include example/functional/flip.cpp
30 #ifdef BOOST_HANA_DOXYGEN_INVOKED
31 constexpr auto flip = [](auto&& f) {
32 return [perfect-capture](auto&& x, auto&& y, auto&& ...z) -> decltype(auto) {
33 return forwarded(f)(forwarded(y), forwarded(x), forwarded(z)...);
41 template <typename X, typename Y, typename ...Z>
42 constexpr decltype(auto) operator()(X&& x, Y&& y, Z&& ...z) const& {
46 static_cast<Z&&>(z)...
50 template <typename X, typename Y, typename ...Z>
51 constexpr decltype(auto) operator()(X&& x, Y&& y, Z&& ...z) & {
55 static_cast<Z&&>(z)...
59 template <typename X, typename Y, typename ...Z>
60 constexpr decltype(auto) operator()(X&& x, Y&& y, Z&& ...z) && {
64 static_cast<Z&&>(z)...
69 constexpr detail::create<flip_t> flip{};
71 BOOST_HANA_NAMESPACE_END
73 #endif // !BOOST_HANA_FUNCTIONAL_FLIP_HPP