From 1649b973fd2ecd6c2398387f8bb5d0d768142336 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 19 Jan 2015 20:58:41 +0100 Subject: QPair: add noexcept to ctors and assignment operators Change-Id: Id201d1f1e7a087083ca6c13ab31c721e672ef566 Reviewed-by: Thiago Macieira --- src/corelib/tools/qpair.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/corelib/tools/qpair.h') diff --git a/src/corelib/tools/qpair.h b/src/corelib/tools/qpair.h index aa0a53388c..d637067fa8 100644 --- a/src/corelib/tools/qpair.h +++ b/src/corelib/tools/qpair.h @@ -45,22 +45,31 @@ struct QPair typedef T1 first_type; typedef T2 second_type; - Q_DECL_CONSTEXPR QPair() : first(), second() {} - Q_DECL_CONSTEXPR QPair(const T1 &t1, const T2 &t2) : first(t1), second(t2) {} + Q_DECL_CONSTEXPR QPair() + Q_DECL_NOEXCEPT_EXPR(noexcept(T1()) && noexcept(T2())) + : first(), second() {} + Q_DECL_CONSTEXPR QPair(const T1 &t1, const T2 &t2) + Q_DECL_NOEXCEPT_EXPR(noexcept(T1(t1)) && noexcept(T2(t2))) + : first(t1), second(t2) {} // compiler-generated copy/move ctor/assignment operators are fine! template - Q_DECL_CONSTEXPR QPair(const QPair &p) : first(p.first), second(p.second) {} + Q_DECL_CONSTEXPR QPair(const QPair &p) + Q_DECL_NOEXCEPT_EXPR(noexcept(T1(p.first)) && noexcept(T2(p.second))) + : 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)) { first = p.first; second = p.second; return *this; } #ifdef Q_COMPILER_RVALUE_REFS template Q_DECL_CONSTEXPR QPair(QPair &&p) // 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))) { first = std::move(p.first); second = std::move(p.second); return *this; } #endif -- cgit v1.2.3