constexpr

    2熱度

    1回答

    我做函數轉換整數或浮弦: #include <functional> #include <string> #include <iostream> template <typename From> inline std::string ToStr(const From& src) { constexpr bool isIntegral = std::is_integral<Fr

    1熱度

    1回答

    理論上,編譯時應該知道類型,編譯器也知道維數。目前,我有一個模板函數,它將矩陣的維度作爲模板參數。我可以通過估算constexpr中的尺寸或通過模板函數來避免這種情況嗎? struct cont {}; void ffd<3>::run(cont mat[3][3][3]) 在理解中,我想避免聲明rows參數。 template<uint8_t rows> struct ffd {

    1熱度

    3回答

    我有一個我經常用於枚舉包裝的類,但是這需要一個cpp文件。誰能告訴我如何使用constexpr 頭文件如下: // Extend-able in the future class CDUVariable { public: enum Value { baud, firmware, type, serial }; static const CDUVari

    4熱度

    1回答

    我有一些舊代碼使用非常類似於str_const描述的here和here來執行一些constexpr字符串操作。 str_const是Scott Schurr描述的一種文字類型,可以從字符串文字構造,因爲它具有const char (&)[]的模板構造函數。 我現在也有一些使用boost::hana的新代碼。 我希望能夠採取hana::string並創建一個引用它的str_const。最簡單的方法是

    3熱度

    2回答

    我遇到以下代碼有問題,我正在編寫一個編譯時平方根函數。代碼編譯最近的鐺鐺6.0。 在最新版本的gcc 8.0上失敗。這個問題似乎與結構的初始化有關。 GCC輸出 error: uninitialized variable 'sqrtNewtonRaphson' in 'constexpr' context } sqrtNewtonRaphson; ^~~~~~~~~~~~~~

    1熱度

    2回答

    int d = 1; constexpr void add() { d++; } int main() { } GCC 7.1將在下面報告錯誤。錯誤信息非常清楚。問題是我在constexpr中沒有看到任何明確的解釋來描述它是非法的。 有人可以解釋規範中定義的規則這種情況下違反嗎? main.cpp: In function 'constexpr void add

    2熱度

    2回答

    編寫基本類型的包裝,我從編譯器這個錯誤: struct Integer { constexpr Integer(int i) : m_i(i) { } constexpr Integer& operator++() { ++m_i; // error: increment of member 'Integer::m_i' in

    5熱度

    1回答

    我想弄清楚是否有性能增益與constexpr而不是通常創建對象。 這是constexpr的代碼片段。 class Rect { const int a; const float b; public: constexpr Rect(const int a,const float b) : a(a),b(b){} }; int main() {

    1熱度

    1回答

    我簡化了我的代碼生成錯誤,並發現,即使這個簡單的計數功能給了我一個錯誤(見下文): #include <boost/hana/tuple.hpp> #include <boost/hana/fold.hpp> #include <boost/hana/plus.hpp> #include <boost/hana/integral_constant.hpp> int main() {

    4熱度

    2回答

    我卡具有以下問題: 鑑於Node<>類型的非終端節點和任意的類型,如A,B等的終端節點所表示的樹(見下文)。 因爲我不想使用運行時多態性我喜歡通過像在下面的例子中立即調用lambda表達式一個constexpr功能樹轉換成std::tuple。 struct A {}; struct B {}; struct C {}; struct D {}; struct E {}; templa