typetraits

    2熱度

    1回答

    我需要使用std::is_assignable類型特徵,這種特徵在我想支持的最老的編譯器版本中不可用。由於我必須自己實現(好吧,我承認它,有一些interwebs偷看),我現在想知道這是我的實現中的錯誤還是std::is_assignable的一般問題。 首先,這是我的測試結構: struct Bar { bool const cb; // this should kill the de

    0熱度

    2回答

    在函數模板的定義中,模板參數的實例通常是未知的。類型特徵可以用來在編譯時獲得一些信息。例如,這裏是is_pointer一個簡單的應用: template <typename T> void foo(T p) { cout << is_pointer<T>::value << endl; } 我的問題是:是否有過一個情況,在非模板功能,其中性狀樣,編譯時功能可以提供有用信息?

    1熱度

    1回答

    我傳遞這兩個簽名,一類爲模板類的模板參數的成員函數的實際指針。有沒有一種方法可以爲操作符重載有這樣的類的專業化?我試圖尋找在type_traits和std::is_copy_assignable有提示,但似乎G ++採用內置插件(__has_trivial_copy爲例)。

    3熱度

    2回答

    在Checking a member exists, possibly in a base class, C++11 version中,我們開發了一個C++ 11版本的經典成員檢查類型特徵SFINAE to check for inherited member functions,它也適用於C++ 11 final類,但使用C++ 11層的功能(即,decltype),得: template<ty

    2熱度

    2回答

    我想實現我自己的is_member_function_pointer,我遇到了麻煩。 namespace __implementation { // integral_constant template<typename T, T v> struct integral_constant { static constexpr T result =

    12熱度

    3回答

    如果一個參數是一個C++函數對象(函數),我該如何推導靜態? template <typename F> void test(F f) {} 我試過is_function<F>::value,但這不起作用。它似乎也沒有is_functor特徵,所以也許這是不可能的。我似乎只是尋找一個特定的成員函數,在這種情況下函數調用操作符:F::operator()。

    0熱度

    1回答

    考慮下面的短節目: #include <type_traits> #include <iostream> using namespace std; template <typename T> void fn(T t) { cout << "T is reference: " << boolalpha << is_reference<T>::value << endl

    9熱度

    3回答

    有沒有辦法用一些C++ 11或最多一個boost庫來做到這一點? #include <iostream> #include <typeinfo> using namespace std; template <typename T> class remove_all_pointers{ public: typedef T type; }; template <typenam

    2熱度

    2回答

    我正在嘗試爲std容器編寫一個流操作符,主要用於調試目的。 我有以下代碼: #include <type_traits> #include <iostream> #include <ostream> #include <iterator> #include <algorithm> #include <functional> #include <vector> #include <s

    12熱度

    1回答

    有一種特質,或者是有可能寫出一個類型特徵is_scoped_enum<T>這樣的: 如果T是一個範圍的列舉,is_scoped_enum<T>::value是true和 如果T是任何其他類型,is_scoped_enum<T>::value是假