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++編譯器中的錯誤嗎?有沒有解決方法?