Skip to content

Commit 63a6299

Browse files
authored
Merge pull request #1270 from SekaiArendelle/fio-vector
Supporting incomplete type for fast_io::vector
2 parents b256638 + 560123e commit 63a6299

File tree

2 files changed

+77
-4
lines changed

2 files changed

+77
-4
lines changed

include/fast_io_dsal/impl/vector.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,10 @@ class vector FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
397397
}
398398

399399
inline constexpr vector(vector const &vec)
400-
requires(::std::is_copy_constructible_v<value_type>)
401400
{
401+
// Using static_assert instead of requires to delay the check
402+
// related to tests/0026.container/0001.vector/recursive.cc
403+
static_assert(::std::is_copy_constructible_v<value_type>, "vector's value type must be copy constructible to use copy constructor");
402404
std::size_t const vecsize{static_cast<std::size_t>(vec.imp.curr_ptr - vec.imp.begin_ptr)};
403405
if (vecsize == 0)
404406
{
@@ -433,10 +435,12 @@ class vector FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
433435
}
434436
des.thisvec = nullptr;
435437
}
436-
inline constexpr vector(vector const &vec) = delete;
438+
437439
inline constexpr vector &operator=(vector const &vec)
438-
requires(::std::copyable<value_type>)
439440
{
441+
// Using static_assert instead of requires to delay the check
442+
// related to tests/0026.container/0001.vector/recursive.cc
443+
static_assert(::std::copyable<value_type>, "vector's value type must be copyable to use copy assignment operator");
440444
if (__builtin_addressof(vec) == this) [[unlikely]]
441445
{
442446
return *this;
@@ -445,7 +449,7 @@ class vector FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
445449
this->operator=(::std::move(newvec));
446450
return *this;
447451
}
448-
inline constexpr vector &operator=(vector const &vec) = delete;
452+
449453
inline constexpr vector(vector &&vec) noexcept
450454
: imp(vec.imp)
451455
{
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include <variant>
2+
#include <fast_io_dsal/vector.h>
3+
4+
struct Base;
5+
6+
struct Node1
7+
{};
8+
struct Node3
9+
{};
10+
11+
struct Node2
12+
{
13+
fast_io::vector<Base> subast;
14+
15+
Node2();
16+
Node2(fast_io::vector<Base> sub);
17+
~Node2();
18+
};
19+
20+
struct Base
21+
{
22+
std::variant<Node1, Node2, Node3> data;
23+
24+
25+
Base(Node1 n) : data(std::move(n))
26+
{}
27+
Base(Node2 n) : data(std::move(n))
28+
{}
29+
Base(Node3 n) : data(std::move(n))
30+
{}
31+
};
32+
33+
Node2::Node2() = default;
34+
Node2::Node2(fast_io::vector<Base> sub) : subast(std::move(sub))
35+
{}
36+
Node2::~Node2() = default;
37+
38+
using Ast = fast_io::vector<Base>;
39+
40+
int main()
41+
{
42+
Ast ast;
43+
ast.emplace_back(Node1{});
44+
ast.emplace_back(Node3{});
45+
46+
47+
Node2 nested;
48+
nested.subast.emplace_back(Node1{});
49+
ast.emplace_back(std::move(nested));
50+
51+
52+
for (auto const &node : ast)
53+
{
54+
std::visit([](auto const &n) {
55+
using T = std::decay_t<decltype(n)>;
56+
if constexpr (std::is_same_v<T, Node1>)
57+
{
58+
}
59+
else if constexpr (std::is_same_v<T, Node2>)
60+
{
61+
}
62+
else if constexpr (std::is_same_v<T, Node3>)
63+
{
64+
}
65+
},
66+
node.data);
67+
}
68+
return 0;
69+
}

0 commit comments

Comments
 (0)