forked from boostorg/type_traits
Apply fix for issue https://svn.boost.org/trac/boost/ticket/9910 which provides a C++11 conforming version of is_convertible.
This commit is contained in:
@ -30,7 +30,9 @@
|
||||
#if defined(__MWERKS__)
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_SFINAE_EXPR) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
# include <boost/utility/declval.hpp>
|
||||
#endif
|
||||
#endif // BOOST_IS_CONVERTIBLE
|
||||
|
||||
// should be always the last #include directive
|
||||
@ -52,7 +54,43 @@ namespace boost {
|
||||
|
||||
namespace detail {
|
||||
|
||||
#if defined(__BORLANDC__) && (__BORLANDC__ < 0x560)
|
||||
#if !defined(BOOST_NO_SFINAE_EXPR) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
|
||||
// This is a C++11 conforming version:
|
||||
|
||||
template <class A, class B, class C>
|
||||
struct or_helper
|
||||
{
|
||||
static const bool value = (A::value || B::value || C::value);
|
||||
};
|
||||
|
||||
template<typename From, typename To, bool b = or_helper<boost::is_void<From>, boost::is_function<To>, boost::is_array<To> >::value>
|
||||
struct is_convertible_basic_impl
|
||||
{
|
||||
// Nothing converts to function or array, but void converts to void:
|
||||
static const bool value = is_void<To>::value;
|
||||
};
|
||||
|
||||
template<typename From, typename To>
|
||||
class is_convertible_basic_impl<From, To, false>
|
||||
{
|
||||
typedef char one;
|
||||
typedef int two;
|
||||
|
||||
template<typename To1>
|
||||
static void test_aux(To1);
|
||||
|
||||
template<typename From1, typename To1>
|
||||
static decltype(test_aux<To1>(boost::declval<From1>()), one()) test(int);
|
||||
|
||||
template<typename, typename>
|
||||
static two test(...);
|
||||
|
||||
public:
|
||||
static const bool value = sizeof(test<From, To>(0)) == 1;
|
||||
};
|
||||
|
||||
#elif defined(__BORLANDC__) && (__BORLANDC__ < 0x560)
|
||||
//
|
||||
// special version for Borland compilers
|
||||
// this version breaks when used for some
|
||||
|
@ -56,6 +56,20 @@ struct bug_5271b
|
||||
|
||||
#endif
|
||||
|
||||
#if ((!defined(BOOST_NO_SFINAE_EXPR) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)) || defined(BOOST_IS_CONVERTIBLE)) && !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
|
||||
struct bug9910
|
||||
{
|
||||
bug9910() = default;
|
||||
bug9910(const bug9910&) = delete; // or private: A(const A&) = default;
|
||||
};
|
||||
struct Ref_bug9910
|
||||
{
|
||||
// proxy reference to bug9910
|
||||
operator bug9910& () { return *_ptr; }
|
||||
bug9910* _ptr;
|
||||
};
|
||||
#endif
|
||||
|
||||
TT_TEST_BEGIN(is_convertible)
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_convertible<Derived,Base>::value), true);
|
||||
@ -192,5 +206,12 @@ BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_convertible<int, bug_5271a>::value), fal
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_convertible<int, bug_5271b>::value), true);
|
||||
#endif
|
||||
|
||||
#if ((!defined(BOOST_NO_SFINAE_EXPR) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)) || defined(BOOST_IS_CONVERTIBLE)) && !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
|
||||
#ifndef _MSC_VER
|
||||
// MSVC gives the wrong answer here, see https://connect.microsoft.com/VisualStudio/feedback/details/858956/std-is-convertible-returns-incorrect-value
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_convertible<Ref_bug9910, bug9910>::value), false);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
TT_TEST_END
|
||||
|
||||
|
Reference in New Issue
Block a user