Mettl C++ 测试框架使用下划线

Mettle C++ Test Framework's use of undescore

看看 mettle 测试框架,他们有这样的代码:

#include <mettle.hpp>
using namespace mettle;

suite<> basic("a basic suite", [](auto &_) {

  _.test("a test", []() {
    expect(true, equal_to(true));
  });

  for(int i = 0; i < 4; i++) {
    _.test("test number " + std::to_string(i), [i]() {
      expect(i % 2, less(2));
    });
  }

  subsuite<>(_, "a subsuite", [](auto &_) {
    _.test("a sub-test", []() {
      expect(true, equal_to(true));
    });
  });

});

下划线的使用有什么特别之处吗?或者它是一个有效的变量名吗?

Is there something special going on with the use of underscore

下划线是可在标识符中使用的有效字符。标识符中下划线的一些使用保留用于实现:What are the rules about using an underscore in a C++ identifier? 但是其中 none 适用于块作用域中的单个下划线。

is it a valid variable name?

在这里,是的。它不会在全局命名空间中。