enable-if

    5熱度

    1回答

    這是我在SFINAE第一次嘗試: #include <type_traits> #include <iostream> struct C1 { using T = int; }; struct C2 { using T = void; }; // For classes that declare T = int template <class C> voi

    4熱度

    1回答

    此問題符合我之前的問題:Generic operator<< ostream C++ for stringifiable class其中我想實現一個通用的<<ostream運算符,該運算符適用於任何擁有to_str()方法的類。 我已成功檢查一個類是否實現to_str()方法,並使用std::cout << stringify(a)感謝此answer。但是,我有困難編寫模板ostream<<運營商

    14熱度

    4回答

    我有一個工程,並使用std::enable_if下面的情況: template<typename T, typename std::enable_if<std::is_same<int, T>::value>::type* = nullptr> void f() { } template<typename T, typename std::enable_if<std:

    6熱度

    3回答

    我試圖定義一個has_ostream_operator<T> SFINAE測試來檢查我是否可以輸出給定的類型。我有它的工作,但只有在我的定義has_ostream_operator我呼籲operator<<作爲一種方法,而不是一箇中綴運營商。換句話說這個工程: decltype(std::declval<std::ostream>().operator<<(std::declval<T>()))>

    2熱度

    2回答

    很多時候我使用過SFINAE,但我有一個非常簡單的例子,我今天無法運行。 class X { public: template <typename CHECK, typename = typename std::enable_if< std::is_floating_point<CHECK>::value, void>::type > void Do()

    0熱度

    2回答

    我有一個模板化函數需要指針。 template <typename T> void foo(const T* bar){} 如何更改foo以確保我正在傳遞迭代器/指針?我假設有一個static_assert或enable_if這樣做的方式,但我似乎無法找到它。

    0熱度

    2回答

    我有一個活動,只有幾個EditText字段包含文本和一個按鈕。 我想按鈕被禁用,除非EditText領域中的至少一個被改變(如有不清楚的地方,換句話說,只有當字段中的至少一個被改變啓動按鈕...) 如何請這樣做?

    0熱度

    2回答

    我有一個模板類看起來像這樣: template <typename T> constexpr bool is_value_passable_v = is_trivially_copyable_v<T> && sizeof(T) <= sizeof(void*) && !is_polymorphic_v<T>; template <typename B, typename T> using par

    1熱度

    2回答

    我已經在這裏實現了這個函數(在一個頭文件中)。 //header.h #include <cstdio> #include <cstdlib> #include <cmath> #include <iostream> #include <stdint.h> #include <type_traits> template < typename T, type

    3熱度

    1回答

    我有這樣的一段代碼,與具有基於什麼不同實現的函數成員可用: #include <vector> template <typename T> struct D { struct inner { T first; }; }; template <> struct D<int> { using inner = std::vector<int>; };