2015-04-15 21:38:15 +00: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-23 19:53:05 +00:00
|
|
|
#include "octa/traits.h"
|
2015-04-18 15:46:44 +00:00
|
|
|
|
2015-04-23 19:53:05 +00:00
|
|
|
namespace octa {
|
2015-04-17 23:11:16 +00:00
|
|
|
template<typename T>
|
2015-04-23 19:53:05 +00:00
|
|
|
static inline constexpr typename RemoveReference<T>::type &&
|
2015-04-17 23:11:16 +00:00
|
|
|
move(T &&v) noexcept {
|
2015-04-23 19:53:05 +00:00
|
|
|
return static_cast<typename RemoveReference<T>::type &&>(v);
|
2015-04-17 23:11:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
static inline constexpr T &&
|
2015-04-23 19:53:05 +00:00
|
|
|
forward(typename RemoveReference<T>::type &v) noexcept {
|
2015-04-17 23:11:16 +00:00
|
|
|
return static_cast<T &&>(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
static inline constexpr T &&
|
2015-04-23 19:53:05 +00:00
|
|
|
forward(typename RemoveReference<T>::type &&v) noexcept {
|
2015-04-17 23:11:16 +00:00
|
|
|
return static_cast<T &&>(v);
|
|
|
|
}
|
2015-04-18 15:46:44 +00:00
|
|
|
|
2015-04-23 19:53:05 +00:00
|
|
|
template<typename T> typename AddRvalueReference<T>::type declval();
|
2015-04-18 16:19:45 +00:00
|
|
|
|
2015-04-18 20:46:31 +00:00
|
|
|
template<typename T> void swap(T &a, T &b) {
|
|
|
|
T c(move(a));
|
|
|
|
a = move(b);
|
|
|
|
b = move(c);
|
|
|
|
}
|
|
|
|
template<typename T, size_t N> void swap(T (&a)[N], T (&b)[N]) {
|
|
|
|
for (size_t i = 0; i < N; ++i) {
|
|
|
|
swap(a[i], b[i]);
|
|
|
|
}
|
|
|
|
}
|
2015-04-15 21:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|