mirror of
https://github.com/boostorg/functional.git
synced 2025-08-02 14:04:27 +02:00
Fix handling of no argument functions in C++11.
When they don't exist it was failing because result_of doesn't have a type and SFINAE couldn't be used as they have no template arguments.
This commit is contained in:
@@ -144,8 +144,30 @@ namespace boost
|
|||||||
: boost::result_of< BOOST_DEDUCED_TYPENAME c<Self>::t() >
|
: boost::result_of< BOOST_DEDUCED_TYPENAME c<Self>::t() >
|
||||||
{ };
|
{ };
|
||||||
|
|
||||||
template< class MD, class F, class FC >
|
// WHen operator()() doesn't have any parameters, it can't
|
||||||
struct forward_adapter_impl<MD,F,FC,0,0>
|
// be templatized and can't use SFINAE, so intead use class
|
||||||
|
// template parameter SFINAE to decide whether to instantiate it.
|
||||||
|
|
||||||
|
template <typename T, typename R = void>
|
||||||
|
struct forward_adapter_sfinae
|
||||||
|
{
|
||||||
|
typedef T type;
|
||||||
|
};
|
||||||
|
|
||||||
|
// This is the fallback for when there isn't an operator()(),
|
||||||
|
// need to create an operator() that will never instantiate
|
||||||
|
// so that using parent::operator() will work okay.
|
||||||
|
template< class MD, class F, class FC, class Enable = void>
|
||||||
|
struct forward_adapter_impl_zero
|
||||||
|
{
|
||||||
|
template <typename T> struct never_instantiate {};
|
||||||
|
template <typename T>
|
||||||
|
typename never_instantiate<T>::type operator()(T) const {}
|
||||||
|
};
|
||||||
|
|
||||||
|
template< class MD, class F, class FC>
|
||||||
|
struct forward_adapter_impl_zero<MD, F, FC,
|
||||||
|
typename forward_adapter_sfinae<typename boost::result_of< FC() >::type>::type>
|
||||||
{
|
{
|
||||||
inline typename boost::result_of< FC() >::type
|
inline typename boost::result_of< FC() >::type
|
||||||
operator()() const
|
operator()() const
|
||||||
@@ -158,6 +180,13 @@ namespace boost
|
|||||||
{
|
{
|
||||||
return static_cast<MD*>(this)->target_function()();
|
return static_cast<MD*>(this)->target_function()();
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template< class MD, class F, class FC >
|
||||||
|
struct forward_adapter_impl<MD,F,FC,0,0>
|
||||||
|
: forward_adapter_impl_zero<MD,F,FC>
|
||||||
|
{
|
||||||
|
using forward_adapter_impl_zero<MD,F,FC>::operator();
|
||||||
|
|
||||||
// closing brace gets generated by preprocessing code, below
|
// closing brace gets generated by preprocessing code, below
|
||||||
|
|
||||||
|
@@ -149,8 +149,31 @@ namespace boost
|
|||||||
: boost::result_of< BOOST_DEDUCED_TYPENAME c<Self>::t() >
|
: boost::result_of< BOOST_DEDUCED_TYPENAME c<Self>::t() >
|
||||||
{ };
|
{ };
|
||||||
|
|
||||||
template< class MD, class F, class FC >
|
// When operator() doesn't have any parameters, it can't
|
||||||
struct lightweight_forward_adapter_impl<MD,F,FC,0,0>
|
// be templatized and can't use SFINAE, so intead use class
|
||||||
|
// template parameter SFINAE to decide whether to instantiate it.
|
||||||
|
|
||||||
|
template <typename T, typename R = void>
|
||||||
|
struct lightweight_forward_adapter_sfinae
|
||||||
|
{
|
||||||
|
typedef T type;
|
||||||
|
};
|
||||||
|
|
||||||
|
// This is the fallback for when there isn't an operator()(),
|
||||||
|
// need to create an operator() that will never instantiate
|
||||||
|
// so that using parent::operator() will work okay.
|
||||||
|
template< class MD, class F, class FC, class Enable = void>
|
||||||
|
struct lightweight_forward_adapter_impl_zero
|
||||||
|
: lightweight_forward_adapter_result
|
||||||
|
{
|
||||||
|
template <typename T> struct never_instantiate {};
|
||||||
|
template <typename T>
|
||||||
|
typename never_instantiate<T>::type operator()(T) const {}
|
||||||
|
};
|
||||||
|
|
||||||
|
template< class MD, class F, class FC>
|
||||||
|
struct lightweight_forward_adapter_impl_zero<MD, F, FC,
|
||||||
|
typename lightweight_forward_adapter_sfinae<typename boost::result_of< FC() >::type>::type>
|
||||||
: lightweight_forward_adapter_result
|
: lightweight_forward_adapter_result
|
||||||
{
|
{
|
||||||
inline typename boost::result_of< FC() >::type
|
inline typename boost::result_of< FC() >::type
|
||||||
@@ -166,6 +189,12 @@ namespace boost
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template< class MD, class F, class FC >
|
||||||
|
struct lightweight_forward_adapter_impl<MD,F,FC,0,0>
|
||||||
|
: lightweight_forward_adapter_impl_zero<MD,F,FC>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
# define BOOST_PP_FILENAME_1 \
|
# define BOOST_PP_FILENAME_1 \
|
||||||
<boost/functional/lightweight_forward_adapter.hpp>
|
<boost/functional/lightweight_forward_adapter.hpp>
|
||||||
# define BOOST_PP_ITERATION_LIMITS \
|
# define BOOST_PP_ITERATION_LIMITS \
|
||||||
|
Reference in New Issue
Block a user