diff --git a/src/ox/std/CMakeLists.txt b/src/ox/std/CMakeLists.txt index c4546fd01..cf518898e 100644 --- a/src/ox/std/CMakeLists.txt +++ b/src/ox/std/CMakeLists.txt @@ -34,6 +34,7 @@ add_library( string.cpp strops.cpp trace.cpp + typetraits.cpp ) if(NOT MSVC) diff --git a/src/ox/std/memory.hpp b/src/ox/std/memory.hpp index 2cfc1c756..fdc92c517 100644 --- a/src/ox/std/memory.hpp +++ b/src/ox/std/memory.hpp @@ -50,14 +50,13 @@ void safeDeleteArray(auto *val) requires(sizeof(*val) >= 1) { delete[] val; } -template struct DefaultDelete { - constexpr void operator()(T *p) noexcept { + constexpr void operator()(auto *p) noexcept { safeDelete(p); } }; -template> +template class UniquePtr { private: diff --git a/src/ox/std/typetraits.cpp b/src/ox/std/typetraits.cpp new file mode 100644 index 000000000..9f38a7913 --- /dev/null +++ b/src/ox/std/typetraits.cpp @@ -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 +struct ConstructableTest { + constexpr ConstructableTest(int) noexcept {} + constexpr ConstructableTest(ConstructableTest&) noexcept requires(copyable) {} + constexpr ConstructableTest(ConstructableTest&&) noexcept requires(moveable) {} +}; + +static_assert(!is_move_constructible_v>); +static_assert(is_move_constructible_v>); +static_assert(!is_move_constructible_v>); +static_assert(is_move_constructible_v>); + +} \ No newline at end of file diff --git a/src/ox/std/typetraits.hpp b/src/ox/std/typetraits.hpp index 1cc38ddc8..4b9031f42 100644 --- a/src/ox/std/typetraits.hpp +++ b/src/ox/std/typetraits.hpp @@ -182,4 +182,22 @@ struct remove_reference { template using remove_reference_t = typename remove_reference::type; +namespace detail { +template +T &&declval(); + +template()))> +constexpr bool is_move_constructible(int) { + return true; +} + +template +constexpr bool is_move_constructible(bool) { + return false; +} +} + +template +constexpr bool is_move_constructible_v = detail::is_move_constructible(0); + }