forked from Mq-b/Loser-HomeWork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jacky.cpp
62 lines (54 loc) · 1.08 KB
/
jacky.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <cstdio>
#include <vector>
inline void dbg(const char* msg)
{
std::puts(msg);
std::fflush(stdout);
}
template <class T, class... Arg>
requires(std::is_same_v<std::remove_cvref_t<T>, std::remove_cvref_t<Arg>> && ...)
auto make_vector(T&& first, Arg&&... args)
{
return std::vector<std::remove_cvref_t<T>>{
{std::forward<T>(first), std::forward<Arg>(args)...}
};
}
struct X {
X() noexcept
{
dbg("X()");
};
~X() noexcept
{
dbg("~X()");
};
X(const X&)
{
dbg("X(const X&)");
}
X(X&&) noexcept
{
dbg("X(X&&)");
}
};
void test()
{
static_assert(requires {
{
make_vector(std::vector{1, 2, 3})
} -> std::same_as<std::vector<std::vector<int>>>;
{
make_vector(1, 2, 3)
} -> std::same_as<std::vector<int>>;
make_vector(1, 2, 3).size() == 3;
});
X x1;
X x2;
auto vec = make_vector(x1, std::move(x2));
auto vec2 = make_vector(std::vector{1, 2, 3});
}
int main()
{
test();
dbg("test end");
}