constexpr

    0熱度

    2回答

    如果我有一個非成員constexpr函數取基準參數它必須是恆定的參考

    1熱度

    2回答

    考慮以下代碼: #include <array> template < int... Ints > constexpr std::array<int,sizeof...(Ints)> theIntArray = {Ints...}; template < size_t NN > constexpr void test(const std::array<int,NN>& xx) {

    5熱度

    1回答

    自從C++ 11以來,我們有constexpr函數,並且自從使用每個新標準(14,1z)以來,它們的限制就越來越少。 然而,在STL最明顯的功能,這可以由constexpr,該cmath/math.h功能,仍然沒有constexpr版本在任何標準庫實現AFAIK。 這是僅僅在C++標準的積壓,還是有其他原因,爲什麼我們仍然沒有constexpr版本的這些功能?

    3熱度

    1回答

    基於this問題,我嘗試了一個is_vector特點: #include <iostream> #include <vector> using namespace std; template<typename T> struct is_vector { constexpr static bool value = false; }; template<typename

    1熱度

    1回答

    我知道,有很多關於靜態(constexpr)成員鏈接的回答問題。 但我想知道,爲什麼在頭文件中使用模板類線外定義,但不適用於專門的類。 a)本工程不鏈接錯誤: template<typename, typename> struct Foobar; template<typename T> struct Foobar<int, T> { static constexpr std::

    6熱度

    4回答

    我希望能夠通過類型的ID創建switch語句。我發現了一種機制,可以爲不同類型提供唯一的ID。這很簡單: template <typename T> struct type { static void id() { } }; template <typename T> constexpr const size_t type_id() { return reinterp

    1熱度

    2回答

    我想知道是否可以通過參數包將簡單循環轉換爲constexpr並使用更簡單的代碼。此代碼示例演示什麼,我試圖做 struct Student { AgeCategory age; Income income; bool is_student; CreditRating credit_rating; bool buys_computer; };

    2熱度

    1回答

    Mike Isaacson在「Exploring C++ 17 and beyond」演示文稿中提到了一個問題(https://youtu.be/-ctgSbEfRxU?t=2907),有關於編寫的問題: const constexpr .... vs single const。 Mike說,在C++ 11中,constexpr暗含了const,而在C++ 14中則沒有。 這是真的嗎? 我試圖

    3熱度

    1回答

    我與static constexpr屬性有一些困難:它與積分類型一起使用,有enum class成員,但是當我嘗試使用靜態初始化的整數數組完成時,它失敗鏈接說undefined reference to S::a裏面main。 這是與鏗3.9或g ++ 6.3和ld 2.27.90;和所有與-std=c++14。 這裏是重現此最快的片段: struct S { static const

    2熱度

    2回答

    我試圖使用str_const類靈感來自https://stackoverflow.com/a/15863826/2859099 #include <cstddef> #include <stdexcept> class str_const { public: template<std::size_t N> constexpr str_const(const char(