From 187edcd1d38f735da5d450496a590a5976a7a813 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 26 Feb 2022 22:53:50 -0600 Subject: [PATCH] [ox/std] Add is_move_constructible --- deps/ox/src/ox/std/CMakeLists.txt | 1 + deps/ox/src/ox/std/memory.hpp | 5 ++--- deps/ox/src/ox/std/typetraits.cpp | 25 +++++++++++++++++++++++++ deps/ox/src/ox/std/typetraits.hpp | 18 ++++++++++++++++++ 4 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 deps/ox/src/ox/std/typetraits.cpp diff --git a/deps/ox/src/ox/std/CMakeLists.txt b/deps/ox/src/ox/std/CMakeLists.txt index c4546fd0..cf518898 100644 --- a/deps/ox/src/ox/std/CMakeLists.txt +++ b/deps/ox/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/deps/ox/src/ox/std/memory.hpp b/deps/ox/src/ox/std/memory.hpp index 2cfc1c75..fdc92c51 100644 --- a/deps/ox/src/ox/std/memory.hpp +++ b/deps/ox/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/deps/ox/src/ox/std/typetraits.cpp b/deps/ox/src/ox/std/typetraits.cpp new file mode 100644 index 00000000..9f38a791 --- /dev/null +++ b/deps/ox/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/deps/ox/src/ox/std/typetraits.hpp b/deps/ox/src/ox/std/typetraits.hpp index 1cc38ddc..4b9031f4 100644 --- a/deps/ox/src/ox/std/typetraits.hpp +++ b/deps/ox/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); + }