mirror of
https://github.com/boostorg/bind.git
synced 2025-07-31 13:27:30 +02:00
Support use of standard placeholders with boost::bind
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include <boost/is_placeholder.hpp>
|
||||
#include <boost/bind/arg.hpp>
|
||||
#include <boost/bind/detail/result_traits.hpp>
|
||||
#include <boost/bind/std_placeholders.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/visit_each.hpp>
|
||||
#include <boost/core/enable_if.hpp>
|
||||
|
39
include/boost/bind/std_placeholders.hpp
Normal file
39
include/boost/bind/std_placeholders.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef BOOST_BIND_STD_PLACEHOLDERS_HPP_INCLUDED
|
||||
#define BOOST_BIND_STD_PLACEHOLDERS_HPP_INCLUDED
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
// Copyright 2021 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/is_placeholder.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) && !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
template<> struct is_placeholder< typename std::decay<decltype(std::placeholders::_1)>::type > { enum _vt { value = 1 }; };
|
||||
template<> struct is_placeholder< typename std::decay<decltype(std::placeholders::_2)>::type > { enum _vt { value = 2 }; };
|
||||
template<> struct is_placeholder< typename std::decay<decltype(std::placeholders::_3)>::type > { enum _vt { value = 3 }; };
|
||||
template<> struct is_placeholder< typename std::decay<decltype(std::placeholders::_4)>::type > { enum _vt { value = 4 }; };
|
||||
template<> struct is_placeholder< typename std::decay<decltype(std::placeholders::_5)>::type > { enum _vt { value = 5 }; };
|
||||
template<> struct is_placeholder< typename std::decay<decltype(std::placeholders::_6)>::type > { enum _vt { value = 6 }; };
|
||||
template<> struct is_placeholder< typename std::decay<decltype(std::placeholders::_7)>::type > { enum _vt { value = 7 }; };
|
||||
template<> struct is_placeholder< typename std::decay<decltype(std::placeholders::_8)>::type > { enum _vt { value = 8 }; };
|
||||
template<> struct is_placeholder< typename std::decay<decltype(std::placeholders::_9)>::type > { enum _vt { value = 9 }; };
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
|
||||
#endif // #ifndef BOOST_BIND_STD_PLACEHOLDERS_HPP_INCLUDED
|
@@ -78,3 +78,4 @@ run bind_cpp20_test.cpp ;
|
||||
run protect_test2.cpp ;
|
||||
run protect_cpp20_test.cpp ;
|
||||
run bind_noexcept_mf2_test.cpp ;
|
||||
run std_placeholders_test.cpp ;
|
||||
|
50
test/std_placeholders_test.cpp
Normal file
50
test/std_placeholders_test.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
// Copyright 2021 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/bind/bind.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <functional>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Skipping test due to BOOST_NO_CXX11_HDR_FUNCTIONAL being defined" )
|
||||
int main() {}
|
||||
|
||||
#elif defined(BOOST_NO_CXX11_DECLTYPE)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Skipping test due to BOOST_NO_CXX11_DECLTYPE being defined" )
|
||||
int main() {}
|
||||
|
||||
#elif defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Skipping test due to BOOST_NO_CXX11_HDR_TYPE_TRAITS being defined" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
int f( int x )
|
||||
{
|
||||
return -x;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
|
||||
BOOST_TEST_EQ( boost::bind( f, _1 )( 1 ), -1 );
|
||||
BOOST_TEST_EQ( boost::bind( f, _2 )( 1, 2 ), -2 );
|
||||
BOOST_TEST_EQ( boost::bind( f, _3 )( 1, 2, 3 ), -3 );
|
||||
BOOST_TEST_EQ( boost::bind( f, _4 )( 1, 2, 3, 4 ), -4 );
|
||||
BOOST_TEST_EQ( boost::bind( f, _5 )( 1, 2, 3, 4, 5 ), -5 );
|
||||
BOOST_TEST_EQ( boost::bind( f, _6 )( 1, 2, 3, 4, 5, 6 ), -6 );
|
||||
BOOST_TEST_EQ( boost::bind( f, _7 )( 1, 2, 3, 4, 5, 6, 7 ), -7 );
|
||||
BOOST_TEST_EQ( boost::bind( f, _8 )( 1, 2, 3, 4, 5, 6, 7, 8 ), -8 );
|
||||
BOOST_TEST_EQ( boost::bind( f, _9 )( 1, 2, 3, 4, 5, 6, 7, 8, 9 ), -9 );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user