-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_scene.h
More file actions
55 lines (45 loc) · 1.51 KB
/
debug_scene.h
File metadata and controls
55 lines (45 loc) · 1.51 KB
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
// debug_scene.h 核心调试框架头文件
#pragma once // 简单粗暴,大部分编译器都支持
// 或者经典的头文件卫士(跨编译器兼容性更好)
#ifndef DEBUG_SCENE_H
#define DEBUG_SCENE_H
#include<iostream>
#include<vector>
#include<string> // 注意:用std::string需要包含这个头文件,你之前漏了!
// 模板测试用例结构体:存数据和描述
template <typename T>
struct test_case_x {
T data;
std::string desc;
};
// 全局模板容器:存储对应类型的所有测试用例(C++11及以上可直接空初始化)
template <typename T>
std::vector<test_case_x<T>> debug_v;
// 修正:返回值改为容器的引用(vector<test_case_x<T>>&),参数改为const左值引用避免拷贝
template <typename T>
std::vector<test_case_x<T>>& createCase(const std::vector<test_case_x<T>>& v) {
// 将传入的测试用例插入全局debug_v容器末尾
debug_v<T>.insert(debug_v<T>.end(), v.begin(), v.end());
// 返回全局容器的引用,方便后续直接使用/链式调用
return debug_v<T>;
}
// 测试环境类
class Environment {
int YourVar; // 自定义成员变量,保留你的原代码
public:
// 构造/析构保留空实现,符合你的原代码
Environment() {}
~Environment() {}
// 修正:循环中补全模板参数,参数改为const引用,循环用const&避免拷贝
template<typename T>
void test(const std::vector<test_case_x<T>>& s) {
std::cout<<"-----debug start" <<std::endl;
// 正确:指定模板参数test_case_x<T>,用const&避免元素拷贝
for (const test_case_x<T>& i : s) {
std::cout << i.desc << "\t" << i.data << std::endl;
}
std::cout<<"-----debug end" <<std::endl;
}
};
// 你的框架所有代码(test_case_x、createCase、Environment等)
#endif // DEBUG_SCENE_H