[ox/std] Add is_move_constructible

This commit is contained in:
Gary Talent 2022-02-26 22:53:50 -06:00
parent 0a48692ee1
commit 187edcd1d3
4 changed files with 46 additions and 3 deletions

View File

@ -34,6 +34,7 @@ add_library(
string.cpp
strops.cpp
trace.cpp
typetraits.cpp
)
if(NOT MSVC)

View File

@ -50,14 +50,13 @@ void safeDeleteArray(auto *val) requires(sizeof(*val) >= 1) {
delete[] val;
}
template<typename T>
struct DefaultDelete {
constexpr void operator()(T *p) noexcept {
constexpr void operator()(auto *p) noexcept {
safeDelete(p);
}
};
template<typename T, typename Deleter = DefaultDelete<T>>
template<typename T, typename Deleter = DefaultDelete>
class UniquePtr {
private:

25
deps/ox/src/ox/std/typetraits.cpp vendored Normal file
View File

@ -0,0 +1,25 @@
/*
* Copyright 2015 - 2022 gary@drinkingtea.net
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "typetraits.hpp"
namespace ox {
template<bool moveable, bool copyable>
struct ConstructableTest {
constexpr ConstructableTest(int) noexcept {}
constexpr ConstructableTest(ConstructableTest&) noexcept requires(copyable) {}
constexpr ConstructableTest(ConstructableTest&&) noexcept requires(moveable) {}
};
static_assert(!is_move_constructible_v<ConstructableTest<false, false>>);
static_assert(is_move_constructible_v<ConstructableTest<true, false>>);
static_assert(!is_move_constructible_v<ConstructableTest<false, true>>);
static_assert(is_move_constructible_v<ConstructableTest<true, true>>);
}

View File

@ -182,4 +182,22 @@ struct remove_reference<T&&> {
template<typename T>
using remove_reference_t = typename remove_reference<T>::type;
namespace detail {
template<typename T>
T &&declval();
template<typename T, typename = decltype(T(declval<T>()))>
constexpr bool is_move_constructible(int) {
return true;
}
template<typename T>
constexpr bool is_move_constructible(bool) {
return false;
}
}
template<class T>
constexpr bool is_move_constructible_v = detail::is_move_constructible<T>(0);
}