forked from Mq-b/Loser-HomeWork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Matrix-A.cpp
55 lines (46 loc) · 1.12 KB
/
Matrix-A.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
#include <cstdio>
#include <vector>
inline void dbg(const char* msg) {
std::puts(msg);
std::fflush(stdout);
}
struct X {
X() noexcept {
dbg("X()");
};
~X() noexcept {
dbg("~X()");
};
X(const X&) {
dbg("X(const X&)");
}
X(X&&) noexcept {
dbg("X(X&&)");
}
};
// 直接宏替换,有没有可能标准库里没有make_vector就是因为可以用初始化器列表
//#define make_vector(...) std::vector{{__VA_ARGS__}}
// 用 emplace_back 函数调用换取拷贝时间
auto make_vector(auto&&... args) {
std::vector<std::common_type_t<decltype(args)...>> temp;
(temp.emplace_back(std::forward<decltype(args)>(args)),...);
return temp;
}
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));
}
int main() {
test();
dbg("test end");
}