mirror of
https://github.com/boostorg/bind.git
synced 2026-08-17 19:01:44 +02:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d67c22ff44 | ||
|
|
e41ba84da8 | ||
|
|
9ce9a7ce99 | ||
|
|
1aac698358 | ||
|
|
3cbcd02965 |
@@ -41,6 +41,18 @@ inline boost::arg<7> _7() { return boost::arg<7>(); }
|
|||||||
inline boost::arg<8> _8() { return boost::arg<8>(); }
|
inline boost::arg<8> _8() { return boost::arg<8>(); }
|
||||||
inline boost::arg<9> _9() { return boost::arg<9>(); }
|
inline boost::arg<9> _9() { return boost::arg<9>(); }
|
||||||
|
|
||||||
|
#elif !defined(BOOST_NO_CXX17_INLINE_VARIABLES)
|
||||||
|
|
||||||
|
BOOST_INLINE_CONSTEXPR boost::arg<1> _1;
|
||||||
|
BOOST_INLINE_CONSTEXPR boost::arg<2> _2;
|
||||||
|
BOOST_INLINE_CONSTEXPR boost::arg<3> _3;
|
||||||
|
BOOST_INLINE_CONSTEXPR boost::arg<4> _4;
|
||||||
|
BOOST_INLINE_CONSTEXPR boost::arg<5> _5;
|
||||||
|
BOOST_INLINE_CONSTEXPR boost::arg<6> _6;
|
||||||
|
BOOST_INLINE_CONSTEXPR boost::arg<7> _7;
|
||||||
|
BOOST_INLINE_CONSTEXPR boost::arg<8> _8;
|
||||||
|
BOOST_INLINE_CONSTEXPR boost::arg<9> _9;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
BOOST_STATIC_CONSTEXPR boost::arg<1> _1;
|
BOOST_STATIC_CONSTEXPR boost::arg<1> _1;
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
//
|
//
|
||||||
// protect.hpp
|
// protect.hpp
|
||||||
//
|
//
|
||||||
// Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
|
// Copyright 2002, 2020 Peter Dimov
|
||||||
// Copyright (c) 2009 Steven Watanabe
|
// Copyright 2009 Steven Watanabe
|
||||||
//
|
//
|
||||||
// Distributed under the Boost Software License, Version 1.0. (See
|
// Distributed under the Boost Software License, Version 1.0. (See
|
||||||
// accompanying file LICENSE_1_0.txt or copy at
|
// accompanying file LICENSE_1_0.txt or copy at
|
||||||
@@ -13,7 +13,8 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#include <boost/detail/workaround.hpp>
|
#include <boost/config/workaround.hpp>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
@@ -21,8 +22,53 @@ namespace boost
|
|||||||
namespace _bi
|
namespace _bi
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_DECLTYPE)
|
||||||
|
|
||||||
|
template<class T> struct protect_make_void
|
||||||
|
{
|
||||||
|
typedef void type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class F, class E = void> struct protect_result_type
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class F> struct protect_result_type< F, typename protect_make_void<typename F::result_type>::type >
|
||||||
|
{
|
||||||
|
typedef typename F::result_type result_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class F> class protected_bind_t: public protect_result_type<F>
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
F f_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
explicit protected_bind_t( F f ): f_( f )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class... A> auto operator()( A&&... a ) -> decltype( f_( std::forward<A>(a)... ) )
|
||||||
|
{
|
||||||
|
return f_( std::forward<A>(a)... );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class... A> auto operator()( A&&... a ) const -> decltype( f_( std::forward<A>(a)... ) )
|
||||||
|
{
|
||||||
|
return f_( std::forward<A>(a)... );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
template<class F> class protected_bind_t
|
template<class F> class protected_bind_t
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
F f_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef typename F::result_type result_type;
|
typedef typename F::result_type result_type;
|
||||||
@@ -286,12 +332,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
F f_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace _bi
|
} // namespace _bi
|
||||||
|
|
||||||
template<class F> _bi::protected_bind_t<F> protect(F f)
|
template<class F> _bi::protected_bind_t<F> protect(F f)
|
||||||
|
|||||||
@@ -75,3 +75,5 @@ run bind_noexcept_mf_test.cpp ;
|
|||||||
run global_placeholders.cpp ;
|
run global_placeholders.cpp ;
|
||||||
run mem_fn_noexcept_test.cpp ;
|
run mem_fn_noexcept_test.cpp ;
|
||||||
run bind_cpp20_test.cpp ;
|
run bind_cpp20_test.cpp ;
|
||||||
|
run protect_test2.cpp ;
|
||||||
|
run protect_cpp20_test.cpp ;
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
// Copyright 2020 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
|
#include <boost/bind/protect.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/config/workaround.hpp>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
BOOST_TEST_EQ( boost::protect( std::plus<int>() )( 1, 2 ), 3 );
|
||||||
|
BOOST_TEST_EQ( boost::protect( std::minus<int>() )( 1, 2 ), -1 );
|
||||||
|
BOOST_TEST_EQ( boost::protect( std::multiplies<int>() )( 1, 2 ), 2 );
|
||||||
|
BOOST_TEST_EQ( boost::protect( std::divides<int>() )( 1, 2 ), 0 );
|
||||||
|
BOOST_TEST_EQ( boost::protect( std::modulus<int>() )( 1, 2 ), 1 );
|
||||||
|
BOOST_TEST_EQ( boost::protect( std::negate<int>() )( 1 ), -1 );
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( boost::protect( std::equal_to<int>() )( 1, 2 ), false );
|
||||||
|
BOOST_TEST_EQ( boost::protect( std::not_equal_to<int>() )( 1, 2 ), true );
|
||||||
|
BOOST_TEST_EQ( boost::protect( std::greater<int>() )( 1, 2 ), false );
|
||||||
|
BOOST_TEST_EQ( boost::protect( std::less<int>() )( 1, 2 ), true );
|
||||||
|
BOOST_TEST_EQ( boost::protect( std::greater_equal<int>() )( 1, 2 ), false );
|
||||||
|
BOOST_TEST_EQ( boost::protect( std::less_equal<int>() )( 1, 2 ), true );
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( boost::protect( std::logical_and<int>() )( 1, 2 ), true );
|
||||||
|
BOOST_TEST_EQ( boost::protect( std::logical_or<int>() )( 1, 2 ), true );
|
||||||
|
BOOST_TEST_EQ( boost::protect( std::logical_not<int>() )( 1 ), false );
|
||||||
|
|
||||||
|
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1600)
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( boost::protect( std::bit_and<int>() )( 1, 2 ), 0 );
|
||||||
|
BOOST_TEST_EQ( boost::protect( std::bit_or<int>() )( 1, 2 ), 3 );
|
||||||
|
BOOST_TEST_EQ( boost::protect( std::bit_xor<int>() )( 1, 2 ), 3 );
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
// protect_test2.cpp
|
||||||
|
//
|
||||||
|
// Copyright 2020 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include <boost/bind/protect.hpp>
|
||||||
|
#include <boost/core/lightweight_test_trait.hpp>
|
||||||
|
#include <boost/core/is_same.hpp>
|
||||||
|
|
||||||
|
template<class T, class F> void test( F )
|
||||||
|
{
|
||||||
|
BOOST_TEST_TRAIT_TRUE((boost::core::is_same<typename T::result_type, typename F::result_type>));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct X
|
||||||
|
{
|
||||||
|
struct result_type {};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Y
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T, class U> struct inherit: T, U
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class F> void test2( F )
|
||||||
|
{
|
||||||
|
// test that F doesn't have ::result_type
|
||||||
|
BOOST_TEST_TRAIT_TRUE((boost::core::is_same<typename inherit<F, X>::result_type, typename X::result_type>));
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test<X>( boost::protect( X() ) );
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_DECLTYPE)
|
||||||
|
|
||||||
|
test2( boost::protect( Y() ) );
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user