forked from boostorg/bind
Define protect(f)::result_type only when F::result_type is defined
This commit is contained in:
@ -24,7 +24,21 @@ namespace _bi
|
|||||||
|
|
||||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_DECLTYPE)
|
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_DECLTYPE)
|
||||||
|
|
||||||
template<class F> class protected_bind_t
|
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:
|
private:
|
||||||
|
|
||||||
@ -32,8 +46,6 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef typename F::result_type result_type;
|
|
||||||
|
|
||||||
explicit protected_bind_t( F f ): f_( f )
|
explicit protected_bind_t( F f ): f_( f )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,29 @@ struct X
|
|||||||
struct result_type {};
|
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()
|
int main()
|
||||||
{
|
{
|
||||||
test<X>( boost::protect( X() ) );
|
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();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user