From 97fd88be62dd456d03f028af572e457aab267092 Mon Sep 17 00:00:00 2001 From: q66 Date: Sat, 18 Apr 2015 00:07:37 +0100 Subject: [PATCH] octa::swap --- octa/utility.h | 13 +++++++++++++ src/new.cpp | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/octa/utility.h b/octa/utility.h index 7274fce..6e28e58 100644 --- a/octa/utility.h +++ b/octa/utility.h @@ -8,6 +8,8 @@ #include +#include "octa/traits.h" + /* must be in std namespace otherwise the compiler won't know about it */ namespace std { template @@ -37,6 +39,17 @@ namespace std { namespace octa { template using InitializerList = std::initializer_list; + + template void swap(T &a, T &b) { + T c(move(a)); + a = move(b); + b = move(c); + } + template void swap(T (&a)[N], T (&b)[N]) { + for (size_t i = 0; i < N; ++i) { + swap(a[i], b[i]); + } + } } #endif \ No newline at end of file diff --git a/src/new.cpp b/src/new.cpp index 4ddd156..51e8262 100644 --- a/src/new.cpp +++ b/src/new.cpp @@ -5,13 +5,13 @@ #include -void *operator new(size_t size) noexcept { +void *operator new(size_t size) { void *p = malloc(size); if (!p) abort(); return p; } -void *operator new[](size_t size) noexcept { +void *operator new[](size_t size) { void *p = malloc(size); if (!p) abort(); return p;