enable-if

    1熱度

    2回答

    我有一個對象的數據庫,並且想在編譯時計算一個特定類型的數量,但是我在編譯時遇到了一些問題。 這裏是我迄今爲止一直在嘗試的一個簡化示例,但是這樣做無法用「error:call to function'do_count'進行編譯,這在模板定義中既不可見也不依賴於參數相關查找」 有沒有更好的方法? #include <cstdint> #include <type_traits> #include

    1熱度

    3回答

    這是我試圖實現的簡化示例。因此,它可能看起來有點傻,但忍受着我。比方說,我有 template<int i> class Class1{ foo(){cout<<"j is divisible by i, so we will hang out"<<endl;} } ,並具有固定int j變量class2:要麼通過這樣一個int或有一個成員變量模板化。我想class2情況下只能夠調用fo

    1熱度

    1回答

    給定一個模板類A,我想定義取決於A的模板參數T_lhs和T_rhs類型T_res: template< typename T_lhs, typename T_rhs > class A { // definition of T_res in case "T_lhs and T_rhs are both not primitive types" template< bool

    0熱度

    2回答

    我有問題,模板: 我有兩個構造函數和方法: 的.cpp: Cell::Cell(sf::Vector2i& uPos, sf::Vector2f& cellDimensions, std::string& stateName) :unitPosition(uPos) { setBasicParameters<std::string>(stateName,cellDimensi

    0熱度

    1回答

    我想創建一個模板類,它將實現一個不同的簽名回調,取決於它是否實例化一種或兩種。 struct NoIntermediate { }; template<typename R, typename I> struct ParserCallbackSwitch { using type = std::function<bool(const std::string &, R&, I&

    0熱度

    1回答

    請幫忙。 我想啓用和有條件地禁用問題類型選擇按鈕 我的代碼是 <ItemTemplate> <asp:Button ID="btn_EditSurveyQuestion" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />  <asp:Button ID="btn_Vi

    3熱度

    1回答

    我有不同的查看類型,其中每個類型都有一個std::size_t View::dimension成員常量和一個typename View::value_type成員類型。 以下編譯類型檢查應該驗證如果兩個From和To是次(使用驗證is_view<>),以及From該內容可以被分配給To。 (相同的尺寸和可轉換價值類型)。 template<typename From, typename To>

    4熱度

    1回答

    我需要學習如何使用enable_if。爲此,我需要使用enable_if重新實現距離函數。我嘗試這樣做: #include <iostream> #include <vector> #include <list> #include <utility> #include <type_traits> template<class In> typename std::enable_if<!

    1熱度

    1回答

    你能告訴我爲什麼這個代碼不能編譯? template <typename T, T minAge, T maxAge, bool isarmed, typename = std::enable_if_t<std::is_arithmetic<T>::value>> class Citizen { public: Citizen(T health, T age); Cit

    0熱度

    2回答

    我正在使用enable_if語句來刪除可能的方法。 #include "gmpxx.h" #include <iostream> template <typename T> struct is_ring_field { }; template <> struct is_ring_field<int> { static const bool value = false;