typetraits

    10熱度

    2回答

    我想要一個模板可以根據某些條件從兩種類型中進行選擇。例如。 struct Base {}; template <typename T1, typename T2> struct test { // e.g. here it should select T1/T2 that is_base_of<Base> typename select_base<T1, T2>::ty

    5熱度

    1回答

    我們何時能夠在g ++中支持standard type properties? libstdC++提供對大多數類型屬性的支持,其中一些需要special GNU extensions的支持。但是,完全支持<type_traits>會很好,我想知道這是什麼時候。我試着詢問libstdC++郵件列表,但不幸的是沒有收到任何迴應。 如果你想知道類型的屬性缺乏支持,這,這裏是其中的一些: 缺少is_tri

    3熱度

    1回答

    auto lambda = [](){ return 7; }; std::result_of<decltype(lambda)()>::type val = lambda(); // 'val' : illegal use of type 'void' 我收到錯誤:'val' : illegal use of type 'void'。爲什麼類型會解析爲無效? 我可能會誤解result_of

    2熱度

    1回答

    所以當我有這樣的代碼模板衍生類型: shared_ptr<Foo> bar (my_normal_operator<Foo>(mumble)); 即使型Foo是走出左外野,它可以作爲返回類型生產僅僅通過一種「添加劑」模式是什麼給出: template <typename Target, typename Source> shared_ptr<Target> my_normal_operato

    1熱度

    1回答

    std::copy<InputInterator, OutputIterator>(/*...*/); 如何確定InputInterator和OutputIterator類型雙打double d[]的陣列?是否有某種iterator_traits<double*>::iterator_type? UPD:我用很舊的編譯器,所以我需要顯式實例

    9熱度

    2回答

    我需要在編譯時計算出可表示特定數字的最小無符號整數類型。事情是這樣的...... ////////////////////////////////////////////////////////////////////////// template<size_t Bits> struct uint_least{}; template<> struct uint_least<8>{ typ

    4熱度

    3回答

    這是正確使用std :: enable_if嗎? 它的作品,但它是正確的? //*.h file template <typename T> static typename std::enable_if<std::is_integral<T>::value, T>::type randomFrom(const T min, const T max); template <typena

    2熱度

    5回答

    在我的模板中,我需要根據typename是否是基本類型來使用不同的代碼部分。 編譯此代碼給出MSVC一個C4067(以下預處理指令意外令牌 - 預計一換行): template <typename T> void MyClass<T>::foo() { // ... some code here #if std::is_fundamental<T>::value if(m_buf

    1熱度

    1回答

    在我的工作中,我們做了大量的結對編程,並且我編寫了一個函數,它只接受一個SINGLE類型的容器或其派生類,但是我的co-工人害怕,因爲它看起來那麼該死的醜陋,並說有一定有一個更好的方式,將失敗的代碼審查: 這裏是簽名,水果類是我改名水果只爲這個線程基類: template <class Container> typename enable_if<is_base_of<Fruit, typenam

    3熱度

    1回答

    像std::reference_wrapper使用指針下方的指針來存儲「引用」,我試圖做類似於下面的代碼。 #include <type_traits> struct Foo { void* _ptr; template<typename T> Foo(T val, typename std::enable_if <