使用auto
- 目的:避免函数调用时的编译器注释。
- 示例:在循环中使用
auto代替int类型,可以减少编译时的注释。 - 示例代码:
for (int num : vectors) { auto num = 1; }
使用static_cast
- 目的:避免函数调用时的注释。
- 示例:在变量初始化或操作时使用
static_cast。 - 示例代码:
static_cast<int>(3.14);
使用const关键字
- 目的:避免函数调用时的注释。
- 示例:在函数参数中使用
const避免编译时注释。 - 示例代码:
const auto& val = 1;
**使用vector和array类型`
- 目的:避免函数调用时的注释。
- 示例:使用
vector或array代替std::vector和std::array。 - 示例代码:
auto v = std::vector<int>(1, 2, 3);
使用std::tie和std::tuple
- 目的:避免函数调用时的注释。
- 示例代码:
std::tuple<int, double> t(1, 2.3);
使用std::make_tuple和std::make_pair
- 目的:避免函数调用时的注释。
- 示例代码:
std::tuple<int, double> t = std::make_tuple(1, 2.3);
使用std::move
- 目的:避免函数调用时的注释。
- 示例代码:
auto& v = std::move({1, 2});
使用std::async和std::await
- 目的:避免函数调用时的注释。
- 示例代码:
auto result = await std::async(std::io::read);
使用std::bind和std::map
- 目的:避免函数调用时的注释。
- 示例代码:
std::map<std::string, int> m; std::bind(std::async(std::tie(m, 1)), std::async, m);
使用std::innermost
- 目的:避免函数调用时的注释。
- 示例代码:
std::innermost(int x = 0, int y = 0) { // 内部代码 }
使用std::ref
- 目的:避免函数调用时的注释。
- 示例代码:
std::ref<int>(1);
使用std::async和std::await结合std::move
- 目的:避免函数调用时的注释。
- 示例代码:
auto result = std::async(std::move(std::io::read()));
使用std::ref代替const ref
- 目的:避免函数调用时的注释。
- 示例代码:
ref<int> r(1);
使用std::auto代替int
- 目的:避免函数调用时的注释。
- 示例代码:
auto x = 1;
使用std::ref代替const ref
- 目的:避免函数调用时的注释。
- 示例代码:
ref<int> r(1);
使用std::async和std::await结合std::ref
- 目的:避免函数调用时的注释。
- 示例代码:
auto result = std::await std::async(std::ref(std::io::read()));
使用std::innermost代替std::tie
- 目的:避免函数调用时的注释。
- 示例代码:
auto result = std::innermost(int x = 0, int y = 0);
使用std::ref代替const ref
- 目的:避免函数调用时的注释。
- 示例代码:
ref<int> r(1);
使用std::ref代替const ref
- 目的:避免函数调用时的注释。
- 示例代码:
ref<int> r(1);
使用std::ref代替const ref
- 目的:避免函数调用时的注释。
- 示例代码:
ref<int> r(1);
这些技巧可以帮助你在代码中减少函数调用时的编译器注释,从而提高代码的运行速度,提升速度需要时间和实践,不要急于求成。




