sfinae

    1熱度

    2回答

    我有類似於Passing different lambdas to function template in c++的問題,但現在使用由std::bind創建的包裝來代替lambda表達式。 我有方法Add兩個重載採取std::function不同的形式: template<typename T> struct Value { T value; }; template <typ

    5熱度

    1回答

    避免編譯此代碼調用不明確: #include <iostream> template <int N> struct TestClass { template <int N2, typename std::enable_if<N2 == N, int>::type = 0> void doAction() { std::cout << "TestClass::doActi

    3熱度

    1回答

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

    2熱度

    1回答

    至少我認爲,下面的代碼片段儘可能直接適用於專業化的SFINAE。 最後一行是主要點,發生故障的位置。專門的foo模板的定義決定了bar模板的專業化程度,或者我想要的。其他bar專業化可以在其他地方定義,或者也許使用任意類型可以簡單地保持不受支持。據我所知,相同的模式被廣泛建議與enable_if一起使用。 template <typename T> struct foo; template

    0熱度

    1回答

    我試圖創建自己的「智能迭代」,我想用SFINAE有根據迭代器的標籤有些運營商: 這裏是我的代碼: template<class Iterator, class Predicat, class Tag> class RangeFilterIterator { public: RangeFilterIterator(Iterator begin, Iterator end, Predic

    3熱度

    1回答

    當我使用SFINAE檢測模板類型是否爲默認可構造時,我剛剛觀察到libC++的一個奇怪問題。 下面是一個小例子,我能夠想出: #include <iostream> #include <type_traits> template <typename T> struct Dummy; template <> struct Dummy<int>{}; template <typena

    2熱度

    2回答

    我一直沒有這樣做過一段時間。我基本上有一個類 template <int L> class MyInteger { //code }; 而具體我想實現像(作爲一種方法) template <int L, int M, int N> MyInteger<N> MyInteger<L>::operator+(const MyInteger<M>& x) const; 但我想限制N是​​

    2熱度

    1回答

    #include <iostream> #include <type_traits> using namespace std; template<typename T> constexpr auto is_pure_input_iterator(int) -> conditional_t < is_convertible_v < iterator_tr

    2熱度

    1回答

    我有一個班級模板Bird與布爾模板參數can_fly。根據該值,我想啓用一個簽名爲void fly();的成員函數。 這是我的代碼: #include <type_traits> template<bool can_fly> class Bird { public: template<typename void_t = typename std::enable_if<can_fl

    11熱度

    2回答

    簡體衰減: // CHAR_TYPE == char, wchar_t, ... template <typename CHAR_TYPE, unsigned CHAR_COUNT> void Foo(CHAR_TYPE const (&value)[CHAR_COUNT]) noexcept { TRACE("const ref array"); // perform