From f4b0691003c817b73d0101846bac1c309b1d5a36 Mon Sep 17 00:00:00 2001 From: q66 Date: Tue, 28 Apr 2015 02:30:17 +0100 Subject: [PATCH] noexcept for functional --- octa/functional.h | 48 +++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/octa/functional.h b/octa/functional.h index 6919c89..97cf046 100644 --- a/octa/functional.h +++ b/octa/functional.h @@ -16,7 +16,8 @@ namespace octa { #define __OCTA_DEFINE_BINARY_OP(name, op, rettype) \ template struct name { \ - bool operator()(const T &x, const T &y) const { return x op y; } \ + bool operator()(const T &x, const T &y) \ + const noexcept(noexcept(x op y)) { return x op y; } \ typedef T first_argument_type; \ typedef T second_argument_type; \ typedef rettype result_type; \ @@ -60,7 +61,8 @@ namespace octa { explicit BinaryNegate(const T &f): p_fn(f) {} bool operator()(const first_argument_type &x, - const second_argument_type &y) { + const second_argument_type &y) + noexcept(noexcept(p_fn(x, y))) { return !p_fn(x, y); } private: @@ -71,19 +73,21 @@ namespace octa { typedef typename T::argument_type argument_type; typedef bool result_type; - explicit UnaryNegate(const T &f): p_fn(f) {} - bool operator()(const argument_type &x) { + explicit UnaryNegate(const T &f) noexcept: p_fn(f) {} + bool operator()(const argument_type &x) noexcept(noexcept(p_fn(x))) { return !p_fn(x); } private: T p_fn; }; - template UnaryNegate not1(const T &fn) { + template UnaryNegate not1(const T &fn) + noexcept(noexcept(UnaryNegate(fn))) { return UnaryNegate(fn); } - template BinaryNegate not2(const T &fn) { + template BinaryNegate not2(const T &fn) + noexcept(noexcept(BinaryNegate(fn))) { return BinaryNegate(fn); } @@ -106,18 +110,22 @@ namespace octa { T *p_ptr; }; - template ReferenceWrapper ref(T &v) { + template + ReferenceWrapper ref(T &v) noexcept { return ReferenceWrapper(v); } - template ReferenceWrapper ref(ReferenceWrapper v) { + template + ReferenceWrapper ref(ReferenceWrapper v) noexcept { return ReferenceWrapper(v); } template void ref(const T &&) = delete; - template ReferenceWrapper cref(const T &v) { + template + ReferenceWrapper cref(const T &v) noexcept { return ReferenceWrapper(v); } - template ReferenceWrapper cref(ReferenceWrapper v) { + template + ReferenceWrapper cref(ReferenceWrapper v) noexcept { return ReferenceWrapper(v); } template void cref(const T &&) = delete; @@ -176,7 +184,7 @@ namespace octa { }; template - __OctaMemFn mem_fn(R T:: *ptr) { + __OctaMemFn mem_fn(R T:: *ptr) noexcept { return __OctaMemFn(ptr); } @@ -334,8 +342,8 @@ namespace octa { template struct Function: __OctaFunction { - Function( ) { initialize_empty(); } - Function(nullptr_t) { initialize_empty(); } + Function( ) noexcept { initialize_empty(); } + Function(nullptr_t) noexcept { initialize_empty(); } Function(Function &&f) { initialize_empty(); @@ -380,7 +388,7 @@ namespace octa { Function(forward(f)).swap(*this); } - void swap(Function &f) { + void swap(Function &f) noexcept { __OctaFmStorage tmp; f.p_stor.manager->call_move_and_destroy(tmp, move(f.p_stor)); p_stor.manager->call_move_and_destroy(f.p_stor, move(p_stor)); @@ -388,7 +396,7 @@ namespace octa { octa::swap(p_call, f.p_call); } - operator bool() const { return p_call != nullptr; } + operator bool() const noexcept { return p_call != nullptr; } private: __OctaFmStorage p_stor; @@ -442,21 +450,21 @@ namespace octa { }; template - void swap(Function &a, Function &b) { + void swap(Function &a, Function &b) noexcept { a.swap(b); } template - bool operator==(nullptr_t, const Function &rhs) { return !rhs; } + bool operator==(nullptr_t, const Function &rhs) noexcept { return !rhs; } template - bool operator==(const Function &lhs, nullptr_t) { return !lhs; } + bool operator==(const Function &lhs, nullptr_t) noexcept { return !lhs; } template - bool operator!=(nullptr_t, const Function &rhs) { return rhs; } + bool operator!=(nullptr_t, const Function &rhs) noexcept { return rhs; } template - bool operator!=(const Function &lhs, nullptr_t) { return lhs; } + bool operator!=(const Function &lhs, nullptr_t) noexcept { return lhs; } } #endif \ No newline at end of file