【问题标题】:Mettle C++ Test Framework's use of undescore [duplicate]Mettl C++ 测试框架使用下划线 [重复]
【发布时间】:2017-06-05 22:53:04
【问题描述】:

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

#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));
    });
  });

});

使用下划线是否有什么特别之处,还是它是一个有效的变量名?

【问题讨论】:

    标签: c++ identifier


    【解决方案1】:

    使用下划线有什么特别之处

    下划线是在标识符中使用的有效字符。标识符中下划线的一些用法是为实现保留的:What are the rules about using an underscore in a C++ identifier? 但这些都不适用于块范围内的单个下划线。

    它是一个有效的变量名吗?

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

    【讨论】:

      猜你喜欢
      • 2011-07-31
      • 1970-01-01
      • 2011-08-07
      • 1970-01-01
      • 2011-10-16
      • 2014-01-17
      • 2020-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多