constexpr

    27熱度

    5回答

    我想在類的內部定義一個常量,其中的值是最大可能的int值。事情是這樣的: class A { ... static const int ERROR_VALUE = std::numeric_limits<int>::max(); ... } 這個聲明失敗,出現以下消息編譯: numeric.cpp:8: error: 'std::numeric_limits:

    0熱度

    3回答

    我無法通過搜索找到答案,因此下一步是詢問。說我有一些像這樣的代碼: template<class Int> inline Int onbit(Int value, int n) { return value | (static_cast<Int>(1) << n); } 如果我調用的代碼,這樣onbit(A, 4),將不斷4通過傳播和優化,或者我應該使它成爲一個模板(templa

    44熱度

    4回答

    struct Test { static const int value = []() -> int { return 0; }(); }; 使用gcc-4.6,我得到類似error: function needs to be constexpr的東西。我嘗試了多種組合,在各個地方放constexpr,但沒有運氣。 是否支持lambda函數constexpr(不管return類型

    4熱度

    2回答

    我知道sizeof...(Args...)產生的C++ 0x被壓縮的模板參數列表中的類型數量,但我想實現它用於演示目的的其他功能,但它不會編譯。 // This is not a solution -- overload ambiguity. // template <typename... Args> size_t num_args(); // Line 7 // template <>