constexpr

    5熱度

    3回答

    考慮以下代碼: struct foo { static constexpr int value = 42; }; void bar(const int* value) { std::cout << *value; } int main() { bar(&foo::value); } 這將編譯下online compilers的couple我想罰款,沒有警告。鑑於沒有單個.c

    0熱度

    1回答

    我可以寫一個constexpr函數執行類型推演但不使用傳遞給它的對象: template <int N> struct Foo { static const int value = N; }; template <typename T> constexpr int get_value(T const &) { return T::value; } void

    0熱度

    3回答

    注:這個問答& A不是對Mersenne twister,但Mersenne numbers。 我想計算,在編譯時,將含有大小爲N梅森素數的陣列(2 Ñ - 1)ñ在[0,N - 1]。 template <std::uint8_t N> static constexpr std::array<std::uint16_t, N> mersenne_numbers() { // Co

    2熱度

    1回答

    前陣子我瞭解到,你可以通過文字轉換爲模板,像這樣: template <int x> class myClass { }; //Later myClass<12> var; 現在我已經定義我自己的int類型,並希望做同樣的事情這一點。 ...但它正在變成頭疼 我想實現....這樣的事情: class myIntType; template <myIntType val> clas

    1熱度

    1回答

    簡單的例子在這裏: static constexpr const char literal1[] = "abcde"; static constexpr const char literal2[] = literal1; 編譯錯誤。如何使它工作,爲什麼不行?

    1熱度

    1回答

    在C++中的引物5,它說, constexpr強加它定義了對象的頂層常量。 那麼,如何可以我宣佈一個constexpr符強加一個低級別的常量,即一個指針指向一個constexpr對象的指針?

    11熱度

    1回答

    考慮下面的代碼的靜態constexpr數據成員初始化的基類的一個靜態constexpr數據成員: : template<typename T> struct S { static constexpr int bar = T::foo; }; struct U: S<U> { static constexpr int foo = 42; }; int main() { } GCC v6

    1熱度

    1回答

    假設我有一個模板類,像這樣: template<typename T, const T* array> struct NullTArrayLength{ static constexpr size_t value = NullTArrayLength<T, array+1>::value; }; /* Some how have a specialization that ter

    36熱度

    1回答

    下面的代碼編譯罰款與GCC: constexpr struct {} s; 但鏘,出現以下錯誤拒絕它: error: default initialization of an object of const type 'const struct (anonymous struct at …)' without a user-provided default constructor 我測試過GC

    5熱度

    1回答

    作爲一個實驗,我只是編寫了一些代碼來編譯時生成std::array<uint32_t, 256>。表格內容本身是一個相當典型的CRC查找表 - 關於唯一的新功能是使用constexpr函數來計算條目,而不是直接在源代碼中放置自動生成的魔術表。 無論如何,這個練習讓我很好奇:在編譯時,編譯器願意做什麼來計算一個constexpr函數或變量的定義會有什麼實際的限制嗎?例如像海灣合作委員會的-ftemp