From 226ce6020ee4eb0ccec744500c350cf54a39f231 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 6 Nov 2015 11:21:19 +0100 Subject: QPair: use std::type_traits for exception specifications This should solve problems with our use of the noexcept operator, because that's how std::pair is defined, too. Mid-term, we should kill QPair and use std::pair instead. It really has gotten way too complicated to implement a C++11 pair correctly. Task-number: QTBUG-48780 Change-Id: Ied0acd220e5131000a957dc356d6efcdd8f83828 Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/tools/qpair.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/corelib/tools/qpair.h b/src/corelib/tools/qpair.h index d637067fa8..b21750f76c 100644 --- a/src/corelib/tools/qpair.h +++ b/src/corelib/tools/qpair.h @@ -46,30 +46,36 @@ struct QPair typedef T2 second_type; Q_DECL_CONSTEXPR QPair() - Q_DECL_NOEXCEPT_EXPR(noexcept(T1()) && noexcept(T2())) + Q_DECL_NOEXCEPT_EXPR((std::is_nothrow_default_constructible::value && + std::is_nothrow_default_constructible::value)) : first(), second() {} Q_DECL_CONSTEXPR QPair(const T1 &t1, const T2 &t2) - Q_DECL_NOEXCEPT_EXPR(noexcept(T1(t1)) && noexcept(T2(t2))) + Q_DECL_NOEXCEPT_EXPR((std::is_nothrow_copy_constructible::value && + std::is_nothrow_copy_constructible::value)) : first(t1), second(t2) {} // compiler-generated copy/move ctor/assignment operators are fine! template Q_DECL_CONSTEXPR QPair(const QPair &p) - Q_DECL_NOEXCEPT_EXPR(noexcept(T1(p.first)) && noexcept(T2(p.second))) + Q_DECL_NOEXCEPT_EXPR((std::is_nothrow_constructible::value && + std::is_nothrow_constructible::value)) : first(p.first), second(p.second) {} template Q_DECL_RELAXED_CONSTEXPR QPair &operator=(const QPair &p) - Q_DECL_NOEXCEPT_EXPR(noexcept(std::declval() = p.first) && noexcept(std::declval() = p.second)) + Q_DECL_NOEXCEPT_EXPR((std::is_nothrow_assignable::value && + std::is_nothrow_assignable::value)) { first = p.first; second = p.second; return *this; } #ifdef Q_COMPILER_RVALUE_REFS template Q_DECL_CONSTEXPR QPair(QPair &&p) + Q_DECL_NOEXCEPT_EXPR((std::is_nothrow_constructible::value && + std::is_nothrow_constructible::value)) // can't use std::move here as it's not constexpr in C++11: - Q_DECL_NOEXCEPT_EXPR(noexcept(T1(static_cast(p.first))) && noexcept(T2(static_cast(p.second)))) : first(static_cast(p.first)), second(static_cast(p.second)) {} template Q_DECL_RELAXED_CONSTEXPR QPair &operator=(QPair &&p) - Q_DECL_NOEXCEPT_EXPR(noexcept(std::declval() = std::move(p.first)) && noexcept(std::declval() = std::move(p.second))) + Q_DECL_NOEXCEPT_EXPR((std::is_nothrow_assignable::value && + std::is_nothrow_assignable::value)) { first = std::move(p.first); second = std::move(p.second); return *this; } #endif -- cgit v1.2.3