[ox/std] Add is_move_constructible
This commit is contained in:
parent
0a48692ee1
commit
187edcd1d3
1
deps/ox/src/ox/std/CMakeLists.txt
vendored
1
deps/ox/src/ox/std/CMakeLists.txt
vendored
@ -34,6 +34,7 @@ add_library(
|
|||||||
string.cpp
|
string.cpp
|
||||||
strops.cpp
|
strops.cpp
|
||||||
trace.cpp
|
trace.cpp
|
||||||
|
typetraits.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
if(NOT MSVC)
|
if(NOT MSVC)
|
||||||
|
5
deps/ox/src/ox/std/memory.hpp
vendored
5
deps/ox/src/ox/std/memory.hpp
vendored
@ -50,14 +50,13 @@ void safeDeleteArray(auto *val) requires(sizeof(*val) >= 1) {
|
|||||||
delete[] val;
|
delete[] val;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct DefaultDelete {
|
struct DefaultDelete {
|
||||||
constexpr void operator()(T *p) noexcept {
|
constexpr void operator()(auto *p) noexcept {
|
||||||
safeDelete(p);
|
safeDelete(p);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T, typename Deleter = DefaultDelete<T>>
|
template<typename T, typename Deleter = DefaultDelete>
|
||||||
class UniquePtr {
|
class UniquePtr {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
25
deps/ox/src/ox/std/typetraits.cpp
vendored
Normal file
25
deps/ox/src/ox/std/typetraits.cpp
vendored
Normal 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>>);
|
||||||
|
|
||||||
|
}
|
18
deps/ox/src/ox/std/typetraits.hpp
vendored
18
deps/ox/src/ox/std/typetraits.hpp
vendored
@ -182,4 +182,22 @@ struct remove_reference<T&&> {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
using remove_reference_t = typename remove_reference<T>::type;
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user