typetraits

    3熱度

    1回答

    我正在計劃最近這是這樣的: - #include <iostream> #include <memory> #include <type_traits> #include <typeinfo> using namespace std; int main() { shared_ptr<int> sp1 = make_shared<int>(5); shared_pt

    3熱度

    1回答

    有沒有辦法檢測到,如果struct有typedef哪個沒有被繼承? ,下面的代碼失敗在C #include <iostream> struct A { }; struct B : public A { typedef A Base; }; struct C : public B {}; template<typename T> struct to_void { typed

    0熱度

    1回答

    我想實現一個模板化函數,以便函數只接受某些特定類型的輸入。我試過std :: enable_if和std :: is_base_of來實現目標。簡化代碼如下所示。代碼編譯並在啓用C++ 11時使用clang ++或g ++運行。但是,當我用Visual Studio 2013進行編譯時,它總是說could not deduce template argument for 'is_base_clas

    2熱度

    3回答

    在我的例子中,我有一個類Foo<T>。在我的函數test中,我需要獲取Foo的模板參數,否則爲正常類型。首先,我開始使用std::conditional,但忘記模板參數必須全部有效,無論選擇哪一個。是爲non-Foo類型創建類型專業化的唯一方法嗎? Example #include <type_traits> template <typename TYPE> class Foo { pu

    6熱度

    1回答

    我正在尋找一個「is_comparable」typetrait,但找不到任何。 構建一個用於檢查某個類的operator==是否已實現的構建非常容易,但是這不包括全局定義的運算符。 是不可能實現is_comparable typetait?

    3熱度

    2回答

    我有一個類模板,接受類型T。它有一個方法。如果它是const和T&,如果它不是const,我希望此方法返回類型T。 template<typename T> class C { static typename add_reference_if_non_const<T>::type method(); }; int main() { assert(is_same<re

    0熱度

    1回答

    如果t是char *或隱式或顯式重寫operator char *()的類,則第一個條件可正確運行。第二個條件的目標是在類型t是一個指針時,執行括號內的代碼,並且可以將t的解除引用類型轉換爲char *。第二個條件在它應該(例如char **應該評估爲true)時不成立。我究竟做錯了什麼? F.Y.I:我只關心一個指針的東西,可以轉換爲一個char *像字符**,而不是與焦炭相關***,如果是有道

    1熱度

    4回答

    我嘗試下面的代碼: #include <iostream> #include <type_traits> int main() { std::cout << std::is_const<std::add_const<int*&>::type>::value; } ,輸出爲0。這是正確的行爲?

    3熱度

    2回答

    我想要寫的函數 template <class T> X foo (T); 其中T是std::pair<X, X>類型。 如何從T推導出返回類型X?

    1熱度

    1回答

    如果類is_standard_layout足夠保證給定的非靜態數據成員始終與對象的地址具有相同的偏移量(即在整個流程範圍內該類的不同實例中相同)?