forked from boostorg/bind
SFINAE out the converting constructor of arg<I> to avoid hard errors with is_convertible on g++ 4.8/4.9
This commit is contained in:
@@ -21,20 +21,27 @@
|
|||||||
|
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#include <boost/is_placeholder.hpp>
|
#include <boost/is_placeholder.hpp>
|
||||||
#include <boost/static_assert.hpp>
|
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
|
|
||||||
|
template< int I, int J > struct _arg_eq
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
template< int I > struct _arg_eq< I, I>
|
||||||
|
{
|
||||||
|
typedef void type;
|
||||||
|
};
|
||||||
|
|
||||||
template< int I > struct arg
|
template< int I > struct arg
|
||||||
{
|
{
|
||||||
BOOST_CONSTEXPR arg()
|
BOOST_CONSTEXPR arg()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class T > BOOST_CONSTEXPR arg( T const & /* t */ )
|
template< class T > BOOST_CONSTEXPR arg( T const & /* t */, typename _arg_eq< I, is_placeholder<T>::value >::type * = 0 )
|
||||||
{
|
{
|
||||||
BOOST_STATIC_ASSERT( I == is_placeholder<T>::value );
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -56,4 +56,7 @@ test-suite "bind"
|
|||||||
[ run bind_type_test.cpp ]
|
[ run bind_type_test.cpp ]
|
||||||
[ run bind_unique_ptr_test.cpp ]
|
[ run bind_unique_ptr_test.cpp ]
|
||||||
[ run bind_nested_rv_test.cpp ]
|
[ run bind_nested_rv_test.cpp ]
|
||||||
|
[ compile arg_copy_test.cpp ]
|
||||||
|
[ compile-fail arg_copy_fail.cpp ]
|
||||||
|
[ run placeholder_std_bind_test.cpp ]
|
||||||
;
|
;
|
||||||
|
19
test/arg_copy_fail.cpp
Normal file
19
test/arg_copy_fail.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
//
|
||||||
|
// arg_copy_fail.cpp - arg<1> to arg<2>
|
||||||
|
//
|
||||||
|
// Copyright 2016 Peter Dimov
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <boost/bind/arg.hpp>
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
boost::arg<1> a1(( boost::arg<2>() ));
|
||||||
|
(void)a1;
|
||||||
|
}
|
34
test/arg_copy_test.cpp
Normal file
34
test/arg_copy_test.cpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
//
|
||||||
|
// arg_copy_test.cpp - copying a custom placeholder _1 to arg<1>
|
||||||
|
//
|
||||||
|
// Copyright 2016 Peter Dimov
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <boost/is_placeholder.hpp>
|
||||||
|
#include <boost/bind/arg.hpp>
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
template<int I> struct ph
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
|
||||||
|
template<int I> struct is_placeholder< ::ph<I> >
|
||||||
|
{
|
||||||
|
enum _vt { value = I };
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
boost::arg<1> a1 = ph<1>();
|
||||||
|
(void)a1;
|
||||||
|
}
|
46
test/placeholder_std_bind_test.cpp
Normal file
46
test/placeholder_std_bind_test.cpp
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
//
|
||||||
|
// placeholder_std_bind_test.cpp - std::bind with Boost's _1
|
||||||
|
//
|
||||||
|
// Copyright 2016 Peter Dimov
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
|
#if defined( BOOST_NO_CXX11_HDR_FUNCTIONAL )
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <boost/bind.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
namespace std
|
||||||
|
{
|
||||||
|
|
||||||
|
template<int N> struct is_placeholder< boost::arg<N> >: public integral_constant<int, N> {};
|
||||||
|
|
||||||
|
} // namespace std
|
||||||
|
|
||||||
|
int foo( int i )
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
BOOST_TEST_EQ( std::bind( foo, _1 )( 1 ), 1 );
|
||||||
|
BOOST_TEST_EQ( std::bind( foo, _2 )( 1, 2 ), 2 );
|
||||||
|
BOOST_TEST_EQ( std::bind( foo, _3 )( 1, 2, 3 ), 3 );
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Reference in New Issue
Block a user