constexpr

    9熱度

    1回答

    據我所知,constexpr是不是圖靈完成不像模板元編程,所以我相信這些是不一樣的。所以問題是constexpr在多大程度上使模板元編程過時了?

    6熱度

    2回答

    我編譯爲LPC1114,一個小的ARM(實際上是Cortex)目標。 RAM比ROM更有限。我使用最新的Mentor(CodeBenchLite)GCC編譯器(GCC 4.6.3)。我有一些我想在ROM中使用的常量對象。據我所知,下面的代碼中的ffx對象應該以ROM(代碼)結尾,但是它被放置在DATA中。 class flop { public: int x; c

    3熱度

    1回答

    我有: constexpr bool is_concurrency_selected()const { return ConcurrentGBx->isChecked();//GBx is a groupbox with checkbox } 和我得到的錯誤: C:\...\Options_Dialog.hpp:129: error: enclosing cla

    22熱度

    2回答

    我想聲明初始化一些常量整數值的constexpr指針,但鐺被挫敗我所有的嘗試: 嘗試1: constexpr int* x = reinterpret_cast<int*>(0xFF); test.cpp:1:20: note: reinterpret_cast is not allowed in a constant expression 嘗試2: constexpr int* x =

    2熱度

    3回答

    是否可以使用C++ 11 initializer_list組裝一遞歸定義類如Foo,下面,使用constexpr構造: template <size_t N> struct Foo { constexpr Foo(int x, Foo<N-1> f) : x(x), xs(xs) {} int x; Foo<N-1> xs; }; template <> st

    5熱度

    2回答

    是否有一種方法可以在編譯時和運行時實現字符串? AFAIK對於需要構造的類需要有一個微不足道的析構函數。但是,當我們處理字符串時,這證明很困難。如果字符串不是constexpr,那麼它需要釋放內存。但是,如果它是constexpr,那麼它是靜態分配的,不應該被刪除,從而允許一個微不足道的析構函數。 但是,不可能說「嘿,編譯器!如果我是constexpr,你不需要破壞我!」或者是? 這將是類似以下內

    9熱度

    3回答

    我有一個constexpr功能,看起來是這樣的: constexpr int foo(int bar) { static_assert(bar>arbitrary_number, "Use a lower number please"); return something_const; } 然而,GCC 4.6.3編譯這個不斷告訴我 錯誤:「棒」不能出現在一個常數表達

    5熱度

    1回答

    我嘗試使用模板專門化來實現編譯時算法選擇。 1散列下面的代碼: template <class C> struct choose { typedef size_t (*type)(const C*); static constexpr type value = java_string_hashcode<C>; }; 我這個專業結構char類

    6熱度

    1回答

    struct X { constexpr static char a1[] = "hello"; // Okay constexpr static const char* a2[] = {"hello"}; // Error }; int main(){} 用gcc編譯給出了錯誤: error: a brace-enclosed initializer is not allowed

    41熱度

    3回答

    我們知道C++ template metaprogramming is Turing complete,但是preprocessor metaprogramming is not。 C++ 11爲我們提供了一種新的元編程形式:計算constexpr函數。這種計算形式是否完成圖靈?我在想,因爲遞歸和條件運算符(?:)在constexpr函數中是允許的,但是我希望有更多專業知識的人來確認。