decltype

    2熱度

    3回答

    我用下面的代碼去檢測給定函數的長參數。 因此,考慮到: int f(int *) { return 0; } 我想提取int *。 這裏是我的嘗試: template<class T, class U> struct SingleArg { typedef U MyArg; }; template<class T, class U> SingleArg<T, U> fT(T (

    5熱度

    2回答

    假設我想開發一個通用庫,該類庫應該可用於數字類型類型,包括double類型和用戶定義類型。 ,我面對現在的問題是,我不知道如何編寫一個函數模板的返回類型很多像這樣的:對於基本類型, template<class T> auto transmogrify(T x) -> ??? { using std::abs; return abs(x)+2.0; } using聲

    4熱度

    2回答

    爲什麼這不起作用(Visual C++ 2012 Update 1),以及修復它的正確方法是什麼? #include <boost/lambda/bind.hpp> namespace bll = boost::lambda; struct Adder { int m; Adder(int m = 0) : m(m) { } int foo(int n) co

    52熱度

    1回答

    我發現代碼here,看上去是這樣的: auto f(T& t, size_t n) -> decltype(t.reserve(n), void()) { .. } 在所有我看過有人告訴我,decltype簽署的文件爲: decltype(entity) 或 decltype(expression) 而且在任何地方都沒有第二個參數。至少這是cppreference上指出的內容。這是declty

    4熱度

    2回答

    Decltype在Visual Studio 2012中確實是錯誤的,還是實際上應該很難使用? 實施例: namespace ptl { struct Test { Test(float){} }; template<class T, class A0> static T* static_constructor(void* p,

    7熱度

    1回答

    我正在爲由任意數量的char標籤進行參數化的表達式編寫模板。 給定一個參數列表,一個工廠函數根據是否有兩個相同類型的參數或者它們是否唯一,返回不同類型的表達式。 一個具體的例子:假設A是一種「加標籤」對象與其operator()重載以產生?Expression<...>。假設a, b, ...被標註爲標籤LabelName<'a'>, LabelName<'b'>, ...。然後A(a,b,c,d

    19熱度

    5回答

    兩個關於decltype和typeof問題: 是否有對decltype和typeof運營商之間有什麼區別? typeof在C++ 11中過時了嗎?

    5熱度

    3回答

    有沒有辦法在C++ 11中比較decltype的結果? 換句話說,這是爲什麼代碼無效: template<typename T, typename U> void func(T& t, U& u) { if(decltype(t) == decltype(u)) { // Some optimised version for this case } else {

    9熱度

    3回答

    這工作功能... auto x = 4; typedef decltype(x) x_t; x_t y = 5; ...那麼,爲什麼不呢? int j = 4; auto func = [&] (int i) { cout << "Hello: i=" << i << " j=" << j << endl;}; typedef decltype(func) lambda_t; lam

    9熱度

    1回答

    // Compiled by Visual Studio 2012 struct A { bool operator ==(const A& other) const { for (decltype(this->n) i = 0; i < n; ++i) // OK {} return true; } protected