constexpr

    3熱度

    5回答

    是否可以在一個點聲明一個常量數組(可能是constexpr),然後在另一個地方定義它,每次只定義一個元素? E.g. extern constexpr int myArray[100]; myArray[0] = myConstexprFunction(0); myArray[1] = myConstexprFunction(1); // ... myArray[100] = myCo

    0熱度

    2回答

    我想要寫代表的這些產物(在數學意義上)一個函數,它接受的形式float(float, float)的功能的任意數量的,併產生一個可調用對象(例如,lambda表達式)功能。 我們能做到這一點,例如,以下列方式: template<typename... BinaryFunctions> auto product_of(BinaryFunctions... fs) { return [=

    0熱度

    1回答

    我想用結構名稱的散列來初始化結構成員。 constexpr uint32_t myHash(const char* const data) { //Some code for hash return myHash; } struct My_Struct{ constexpr Test() : ID(myHash("My_Struct")) { }

    7熱度

    1回答

    我想要一個static constexpr數組類元素的模板類內類似於以下代碼的靜態constexpr模板陣列構件這個例子,但它已經顯示了這個問題。如果我編譯這個機智gcc我得到一個遞歸依賴性的錯誤: test.cc: In instantiation of ‘constexpr Element Template<true>::element [2]’: test.cc:11:27: recurs

    0熱度

    1回答

    我正在使用constexpr來聲明std :: array的大小。 constexprt auto sizearr = 99; 根據對sizearr我想找到用來遍歷數組 char offset; //Class member 指數的類型時sizearr改爲 constexprt auto sizearr = 65000; 編譯時類型推導我想偏移自動申報作爲int類型而不是手動更改爲in

    1熱度

    1回答

    我目前正在進入更多的C++ 11的東西,跳躍constexpr。在我的一本書有人說,你應該以這種方式使用它的常數π一樣,例如: #include <cmath> // (...) constexpr double PI = atan(1) * 4; 現在我想把那個在自己的命名空間,例如。 MathC: // config.h #include <cmath> namespace

    0熱度

    1回答

    我可以在C++頭文件中定義以下函數,然後將其包含在不同的.cc文件中。 我不知道編譯器是否總是訴諸同一個str地址,或者它可能不同,或者它是未定義的行爲? inline constexpr const char *GetCompilerOptions() { return "" #ifdef __AVX__ "AVX," #endif // __AVX__

    3熱度

    1回答

    #include <iostream> using namespace std; template<const int arr[]> struct S { static constexpr int value = arr[0]; }; constexpr int arr[] = { 5 }; int main() { cout << S<arr>::valu

    8熱度

    1回答

    我看到在Quora的C++中聲明瞭一個參考變量作爲常量。 static constexpr const int& r = 3; 那麼,爲什麼這兩個constexpr和const在單個語句中使用? 這種類型的聲明的目的是什麼?

    4熱度

    1回答

    允許聲明一個非const引用爲constexpr?示例代碼: int x = 1; constexpr int& r = x; 這是通過gcc和鐺接受(我試圖兩者的幾個當前和過去的版本,回到C++ 11,和所有接受了它)。然而,我認爲它不應該被接受,因爲C++ 14 [dcl.constexpr/9]表示:如果constexpr說明符以引用聲明使用 ,則出現在其初始值設定每全 表達應是一個常