template-specialization

    6熱度

    1回答

    考慮以下情況: #include <iostream> template <class T> void f(T) { std::cout << "#1\n"; } // #1 template <> void f(const int) { std::cout << "#2\n"; } // #2 int main() { f<const int>(1); // call #1

    15熱度

    2回答

    說我有我的代碼結構是這樣的: 那麼header1.h template <class T, template<class> class C> struct metafunction { using type = typename C<T>::type; }; inline namespace msn { template <class T> struct impleme

    1熱度

    2回答

    如何針對各種標量值專門化很多模板? (如int,float,size_t,uint32_t和在stdint標題中定義的類型)? 我可以避免爲每種類型專門化每個模板嗎? 如果可能,我不想使用boost或其他非標準庫。 那裏template specialization for a set of types有一些解決方案: 替換每個模板具有多種功能。每種標量類型都有一個函數。 (但是有很多模板,這意味

    1熱度

    1回答

    如何爲具有std :: enable_if參數的模板類編寫外聯析構函數體? (我需要這個寫一個裝飾器,爲其他對象類型添加一個標識符)。 代碼: template<typename T, typename std::enable_if<std::is_base_of<X,T>::value>::type* = nullptr> class IdentifiedInstance: public T

    5熱度

    3回答

    我想爲std::string參數創建一個專門的構造函數,但當我用字符串參數調用它時總是使用另一個。 struct Literal : Expression { template <typename V> Literal(V val) { value = val; } }; template <> Literal::Literal(st

    0熱度

    1回答

    模板函數我有一個模板函數: template<typename T> void foo(T const & t); 而且該函數的一些特例: template<> void foo<int>(int const & t) { cout << t << endl; } template<> void foo<const char *>(const char * const & t

    3熱度

    1回答

    我有一個需要訪問其模板類型的特徵的通用算法。有一個特質類可以專門用於提供這些特徵。 在我的課堂中使用這個算法時,我想使用它在類中定義的私有類型。 但是,專業化只能發生在namespace或全球範圍內,我的班級無法訪問。 class A { struct Secret {}; }; template <typename T> struct Trait {}; // I

    4熱度

    4回答

    考慮以下幾點: template <class...> struct MyT; template <class T> struct MyT<T> {}; template <template <class> class TT = MyT> struct A {}; // fine using B = A<MyT>; // does not compile int main()

    2熱度

    2回答

    我在這裏做了一個小型的研究,這需要在某個階段,我有不同的類在某些數據上做(或不做)操作,這取決於它的常量。 一個小例子是這樣的(http://coliru.stacked-crooked.com/a/75c29cddbe6d8ef6) #include <iostream> template <class T> class funny { public: funny(T& a)

    1熱度

    1回答

    我想問你最近幾天我遇到的編程頭痛的幫助。讓我試着解釋我即將實施的內容... 我的目標是定義一組有效的等式。讓我更詳細地解釋... 我認爲是每個方程對象的仿函數 - 定義operator()的類。該運算符的定義應該針對每個方程類型專門定義。專業化包含計算本身: .H: enum class IDs : int { A = 0, B = 1, C = 2 }; template<IDs WHICH