Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-26 08:26:31

0001 #ifndef BOOST_COMPAT_BIND_BACK_HPP_INCLUDED
0002 #define BOOST_COMPAT_BIND_BACK_HPP_INCLUDED
0003 
0004 // Copyright 2024 Peter Dimov
0005 // Distributed under the Boost Software License, Version 1.0.
0006 // https://www.boost.org/LICENSE_1_0.txt
0007 
0008 #include <boost/compat/invoke.hpp>
0009 #include <boost/compat/type_traits.hpp>
0010 #include <boost/compat/integer_sequence.hpp>
0011 #include <boost/compat/detail/returns.hpp>
0012 #include <boost/config.hpp>
0013 #include <boost/config/workaround.hpp>
0014 #include <tuple>
0015 #include <utility>
0016 
0017 namespace boost {
0018 namespace compat {
0019 
0020 namespace detail {
0021 
0022 #if BOOST_WORKAROUND(BOOST_MSVC, < 1910)
0023 # pragma warning(push)
0024 # pragma warning(disable: 4100) // 'a': unreferenced formal parameter
0025 #endif
0026 
0027 template<class F, class A, class... B, std::size_t... I>
0028 static constexpr auto invoke_bind_back_( F&& f, A&& a, index_sequence<I...>, B&&... b )
0029     BOOST_COMPAT_RETURNS( compat::invoke( std::forward<F>(f), std::forward<B>(b)..., std::get<I>( std::forward<A>(a) )... ) )
0030 
0031 #if BOOST_WORKAROUND(BOOST_MSVC, < 1910)
0032 # pragma warning(pop)
0033 #endif
0034 
0035 template<class F, class... A> class bind_back_
0036 {
0037 private:
0038 
0039     F f_;
0040     std::tuple<A...> a_;
0041 
0042 public:
0043 
0044     template<class F2, class... A2>
0045     constexpr bind_back_( F2&& f2, A2&&... a2 ): f_( std::forward<F2>(f2) ), a_( std::forward<A2>(a2)... ) {}
0046 
0047 public:
0048 
0049     template<class... B> BOOST_CXX14_CONSTEXPR auto operator()( B&&... b ) &
0050         BOOST_COMPAT_RETURNS( detail::invoke_bind_back_( f_, a_, make_index_sequence<sizeof...(A)>(), std::forward<B>(b)... ) )
0051 
0052     template<class... B> constexpr auto operator()( B&&... b ) const &
0053         BOOST_COMPAT_RETURNS( detail::invoke_bind_back_( f_, a_, make_index_sequence<sizeof...(A)>(), std::forward<B>(b)... ) )
0054 
0055     template<class... B> BOOST_CXX14_CONSTEXPR auto operator()( B&&... b ) &&
0056         BOOST_COMPAT_RETURNS( detail::invoke_bind_back_( std::move(f_), std::move(a_), make_index_sequence<sizeof...(A)>(), std::forward<B>(b)... ) )
0057 
0058     template<class... B> constexpr auto operator()( B&&... b ) const &&
0059         BOOST_COMPAT_RETURNS( detail::invoke_bind_back_( std::move(f_), std::move(a_), make_index_sequence<sizeof...(A)>(), std::forward<B>(b)... ) )
0060 };
0061 
0062 } // namespace detail
0063 
0064 template<class F, class... A> constexpr auto bind_back( F&& f, A&&... a ) -> detail::bind_back_< decay_t<F>, decay_t<A>... >
0065 {
0066     return { std::forward<F>(f), std::forward<A>(a)... };
0067 }
0068 
0069 } // namespace compat
0070 } // namespace boost
0071 
0072 #endif // BOOST_COMPAT_BIND_BACK_HPP_INCLUDED