2015-04-15 23:38:15 +02:00
|
|
|
/* Utilities for OctaSTD.
|
|
|
|
*
|
|
|
|
* This file is part of OctaSTD. See COPYING.md for futher information.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OCTA_UTILITY_H
|
|
|
|
#define OCTA_UTILITY_H
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
2015-04-25 17:13:21 +02:00
|
|
|
#include "octa/type_traits.h"
|
2015-04-18 17:46:44 +02:00
|
|
|
|
2015-04-23 21:53:05 +02:00
|
|
|
namespace octa {
|
2015-04-18 01:11:16 +02:00
|
|
|
template<typename T>
|
2015-04-24 20:43:20 +02:00
|
|
|
static inline constexpr RemoveReference<T> &&
|
2015-04-18 01:11:16 +02:00
|
|
|
move(T &&v) noexcept {
|
2015-04-24 20:43:20 +02:00
|
|
|
return static_cast<RemoveReference<T> &&>(v);
|
2015-04-18 01:11:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
static inline constexpr T &&
|
2015-04-24 20:43:20 +02:00
|
|
|
forward(RemoveReference<T> &v) noexcept {
|
2015-04-18 01:11:16 +02:00
|
|
|
return static_cast<T &&>(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
static inline constexpr T &&
|
2015-04-24 20:43:20 +02:00
|
|
|
forward(RemoveReference<T> &&v) noexcept {
|
2015-04-18 01:11:16 +02:00
|
|
|
return static_cast<T &&>(v);
|
|
|
|
}
|
2015-04-18 17:46:44 +02:00
|
|
|
|
2015-04-24 20:43:20 +02:00
|
|
|
template<typename T> AddRvalueReference<T> declval();
|
2015-04-18 18:19:45 +02:00
|
|
|
|
2015-04-28 19:48:58 +02:00
|
|
|
template<typename T> void swap(T &a, T &b)
|
|
|
|
noexcept(IsNothrowMoveConstructible<T>::value
|
|
|
|
&& IsNothrowMoveAssignable<T>::value) {
|
2015-04-18 22:46:31 +02:00
|
|
|
T c(move(a));
|
|
|
|
a = move(b);
|
|
|
|
b = move(c);
|
|
|
|
}
|
2015-04-28 19:48:58 +02:00
|
|
|
template<typename T, size_t N> void swap(T (&a)[N], T (&b)[N])
|
|
|
|
noexcept(noexcept(swap(*a, *b))) {
|
2015-04-18 22:46:31 +02:00
|
|
|
for (size_t i = 0; i < N; ++i) {
|
|
|
|
swap(a[i], b[i]);
|
|
|
|
}
|
|
|
|
}
|
2015-04-15 23:38:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|