static-assert

    1热度

    1回答

    使用static_assert当我使用NetBeans开发Java/JNI/C++应用程序。在我的C++类,我使用static_assert和Netbeans显示错误: static_assert(myvariable == 2, "My test.") ; 的错误是: Unable to resolve identifier static_assert 是的,我已经包括了 “type_t

    0热度

    1回答

    如果​​为0,则按预期工作(从列表中获取索引类型)。如果1 static_assert()总是跳闸。我会认为static_assert()只会发生在所有的typename都用完了。为什么不是这样? #define USE_STATIC_ASSERT 1 template <unsigned int I, typename ...Ts> struct items; template <typ

    2热度

    2回答

    我有这个功能实现零覆盖的东西,它使用static_assert来检查,如果给定的事情的类型是POD类型: template <bool safeMode = true, typename generic> void overwriteWithZeros(generic *variableAddress) { if (safeMode) static_assert(std::is_po

    1热度

    1回答

    所以,我正在寻找一种方法来导致编译时错误,如果在声明对象时使用的值等于另一个值(不希望使用C的assert宏)。 是的,我知道为什么会出现这个问题......当他/她抱怨expression did not evaluate to a constant时编译器很清楚。 我也不想让我的整个班级成为模板。有没有一个奇迹的解决方法,我错过了? #include <iostream> class te

    3热度

    2回答

    我注意到的static_assert奇怪的行为: #include <iostream> template <typename T, unsigned int D> struct Vec { static_assert(D && 0, "Invalid dimension for vector!"); }; template <typename T> struct Vec<T

    0热度

    2回答

    我有一个模板化函数需要指针。 template <typename T> void foo(const T* bar){} 如何更改foo以确保我正在传递迭代器/指针?我假设有一个static_assert或enable_if这样做的方式,但我似乎无法找到它。

    3热度

    3回答

    我有一个功能,看起来像这样: int div_round_up(int x, int y) { /** * This function only works for positive divisor and non-negative dividend!! */ assert(y > 0 && x >= 0); if (x == 0) r

    0热度

    1回答

    考虑以下的模板: template <typename T> void foo() { static_assert(sizeof(T) == 0, "Now what?"); } 标准(§7.4)表示: [如果到static_assert条件为假]程序(1.4)应包括 字符串文本的文本,[...] (从https://stackoverflow.com/a/11048906/56

    1热度

    1回答

    的大小静态断言我试图把一个静态断言静态常量unordered_map成员的大小。但是,我得到一个错误,说静态断言的非const条件。有人可以帮忙吗? #include<unordered_map> #include<string> using namespace std; class A{ public: static const unordered_map<str

    0热度

    1回答

    当编译这行代码在Visual Studio 2013: static_assert(!std::is_abstract<int>(), "test"); 此编译器输出错误: expected constant expression 但该代码片段作为this SO question中的答案呈现。这是MSVC++编译器中的错误吗?有没有解决方法?