From 560123e2ca1fb29856793180a1a030d23b98fb35 Mon Sep 17 00:00:00 2001 From: Arendelle Date: Tue, 7 Apr 2026 23:55:31 +0800 Subject: [PATCH] Supporting incomplete type for fast_io::vector --- include/fast_io_dsal/impl/vector.h | 12 ++-- tests/0026.container/0001.vector/recursive.cc | 69 +++++++++++++++++++ 2 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 tests/0026.container/0001.vector/recursive.cc diff --git a/include/fast_io_dsal/impl/vector.h b/include/fast_io_dsal/impl/vector.h index a3f90a75b..9c8520c14 100644 --- a/include/fast_io_dsal/impl/vector.h +++ b/include/fast_io_dsal/impl/vector.h @@ -397,8 +397,10 @@ class vector FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE } inline constexpr vector(vector const &vec) - requires(::std::is_copy_constructible_v) { + // Using static_assert instead of requires to delay the check + // related to tests/0026.container/0001.vector/recursive.cc + static_assert(::std::is_copy_constructible_v, "vector's value type must be copy constructible to use copy constructor"); std::size_t const vecsize{static_cast(vec.imp.curr_ptr - vec.imp.begin_ptr)}; if (vecsize == 0) { @@ -433,10 +435,12 @@ class vector FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE } des.thisvec = nullptr; } - inline constexpr vector(vector const &vec) = delete; + inline constexpr vector &operator=(vector const &vec) - requires(::std::copyable) { + // Using static_assert instead of requires to delay the check + // related to tests/0026.container/0001.vector/recursive.cc + static_assert(::std::copyable, "vector's value type must be copyable to use copy assignment operator"); if (__builtin_addressof(vec) == this) [[unlikely]] { return *this; @@ -445,7 +449,7 @@ class vector FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE this->operator=(::std::move(newvec)); return *this; } - inline constexpr vector &operator=(vector const &vec) = delete; + inline constexpr vector(vector &&vec) noexcept : imp(vec.imp) { diff --git a/tests/0026.container/0001.vector/recursive.cc b/tests/0026.container/0001.vector/recursive.cc new file mode 100644 index 000000000..b23df0d24 --- /dev/null +++ b/tests/0026.container/0001.vector/recursive.cc @@ -0,0 +1,69 @@ +#include +#include + +struct Base; + +struct Node1 +{}; +struct Node3 +{}; + +struct Node2 +{ + fast_io::vector subast; + + Node2(); + Node2(fast_io::vector sub); + ~Node2(); +}; + +struct Base +{ + std::variant data; + + + Base(Node1 n) : data(std::move(n)) + {} + Base(Node2 n) : data(std::move(n)) + {} + Base(Node3 n) : data(std::move(n)) + {} +}; + +Node2::Node2() = default; +Node2::Node2(fast_io::vector sub) : subast(std::move(sub)) +{} +Node2::~Node2() = default; + +using Ast = fast_io::vector; + +int main() +{ + Ast ast; + ast.emplace_back(Node1{}); + ast.emplace_back(Node3{}); + + + Node2 nested; + nested.subast.emplace_back(Node1{}); + ast.emplace_back(std::move(nested)); + + + for (auto const &node : ast) + { + std::visit([](auto const &n) { + using T = std::decay_t; + if constexpr (std::is_same_v) + { + } + else if constexpr (std::is_same_v) + { + } + else if constexpr (std::is_same_v) + { + } + }, + node.data); + } + return 0; +}