小编use*_*392的帖子

google test/mock vs boost vs catch支持c ++ 14/c ++ 17

我正在评估哪种测试框架对我来说是理想的.选择是这三个中:google test,boost.test和catch.

我想要一些没有那么多依赖项的健壮的东西,并且如果需要它能够支持C++ 14/C++ 17.

另一个问题,您是否知道航空电子/航天领域的大公司使用哪些框架?

c++ testing tdd frameworks unit-testing

8
推荐指数
1
解决办法
5459
查看次数

C++运行时类型切换(避免切换)

我已经使用C++几年了,但我还没有找到解决我经常遇到的问题的方法.知道如何解决它会很棒.

我现在所拥有的是:

// Client code:
switch(currentEnumValue)
    {
    case MyEnum::kValue01:
      processData<MyEnum::kValue01>(data);
      break;
    case MyEnum::kValue02:
      processData<MyEnum::kValue02>(data);
      break;
    default:
      LOG("Invalid command");
      break;
    }

// Declarations

enum class MyEnum {kValue01, kValue02};
class MyClass
{
// code
template <MyEnum> void processData(char*); /* Implemented somewhere else */
}
  template <> void MyClass::processData<MyEnum::kValue01>(char* data); /* Implemented somewhere else */
  MyClass <> void MyClass::processData<MyEnum::kValue02>(char* data); /* Implemented somewhere else */
Run Code Online (Sandbox Code Playgroud)

我想删除开关因为很多原因.而不是我需要的东西,如:processData<runtime-decltype(currentEnumValue)>(data);

我知道关于typeid以及没有将编译时间和运行时混合在一起......但尽管如此,我还是希望找到一些解决方案,最好不包括宏.

c++ templates types runtime switch-statement

7
推荐指数
2
解决办法
1467
查看次数

是否可以在声明后设置 constexpr 数组中元素的值?

是否可以constexpr在某一点声明一个 const 数组(可能),然后在另一个地方定义它,一次一个元素?

例如

extern constexpr int myArray[100];


myArray[0] = myConstexprFunction(0);
myArray[1] = myConstexprFunction(1);
// ...
myArray[100] = myConstexprFunction(100);
Run Code Online (Sandbox Code Playgroud)

我正在尝试做的将需要这样的东西。也许可以使用以下内容:http : //b.atch.se/posts/constexpr-counter/

但是如果这种技术在下一个 C++ 标准中是非法的(我希望不是),我想使用更安全的技术。

[编辑]放宽一些要求怎么样..假设我想做这样的事情:

constexpr int myConstExprFunction(int arg) { return arg + 100;}
// other code...
constexpr int a = myConstExprFunctionBegin(10);
constexpr int b = myConstExprFunction(20);
constexpr int c = myConstExprFunction(30);
constexpr int d = myConstExprFunctionEnd(40);
Run Code Online (Sandbox Code Playgroud)

我想要的是 myConstExprFunctionEnd 能够使用先前函数创建的值生成最终数组。当然,一切都在编译时。

[EDIT2] C++11 解决方案非常受欢迎

c++ arrays constexpr c++11

6
推荐指数
2
解决办法
1468
查看次数

std ::有条件的SFINAE

是否可以创建某种std :: enable_if_and_else,如std :: conditional,但没有针对未定义类的编译时错误。

这是一个例子:

static constexpr bool myExpr = true;

struct A {};
struct B;

struct C :
    std::conditional<myExpr,
      A,
      B>::type
    {};  // Compilation error: B is declared but not defined

struct D :
    enable_if_else<myExpr,
      A,
      B>::type
    {};  // It works
Run Code Online (Sandbox Code Playgroud)

谢谢

c++ sfinae enable-if template-meta-programming c++11

1
推荐指数
1
解决办法
459
查看次数