decltype

    6熱度

    4回答

    我知道這在C++ 03中是不可能的,但我希望有一些新的巫術允許我這樣做。見下: template <class T> struct Binder { template<typename FT, FT T::*PtrTomember> void AddMatch(); }; struct TestType { int i; }; int main(int

    0熱度

    2回答

    我有以下函數創建迭代器的std::vector到另一個容器: template <typename T, template <typename, typename = std::allocator<T>> class Con> std::vector<typename Con<T>::iterator> make_itervec(Con<T>& v) { std::ve

    6熱度

    1回答

    如何在以下示例中獲取成員函數的返回類型? template <typename Getter> class MyClass { typedef decltype(mygetter.get()) gotten_t; ... }; 問題當然是我定義MyClass時沒有「mygetter」對象。 我想要做的是:我創建一個緩存,可以使用,因爲它的關鍵,無論是由getter返回。

    4熱度

    1回答

    我有: #include <type_traits> #include <stdio.h> void f() { printf("foo\n"); } int main() { printf("%d %d %d\n", std::is_same<decltype(*&f),decltype(f)>::value, std::is_function<decl

    0熱度

    1回答

    我想用C++ 11多線程化我的部分代碼。 我創建這樣一羣RNG年代: typedef std::mt19937 mersenne_twister; typedef std::uniform_real_distribution<double> unidist; // 8 rng engines with 8 consecutive seeds const size_t Nrng = 8;

    1熱度

    1回答

    following code的編譯在MSVC++,但在GCC 4.5.1不編譯的聲明中的模板類型規範的一部分: #include <iostream> template< typename PT, bool pB > struct TA { PT m; TA(PT fT) : m(fT) { std::cout << "TA<" << pB

    3熱度

    1回答

    typedef decltype(true ? (long&&)0 : (long&&)0) T; T應該是什麼? 根據gcc(4.7),它是long。根據叮咚(主幹),它是long&&。這種差異導致clang無法編譯使用gcc 4.7的libstdC++的代碼。誰是對的? UPDATE:作爲ildjarn指出,鏘是正確的,並作爲理查德史密斯指出,錯誤的libstdC++是由於在標準的錯誤。這

    1熱度

    3回答

    VS2010部分支持C++ 11。我在VS2010 RTM中編譯下面的代碼。我很困惑爲什麼代碼CLS()被分析到不同的含義。在「decltype(CLS())obj1;」行中,CLS()表示一個類對象實體。但是在「CLS obj2(CLS());」一行中,CLS()表示一個函數指針,該函數指針不帶參數地回退CLS對象。行爲是否預期?它在標準中有描述嗎? struct CLS { int

    2熱度

    2回答

    訪問靜態字段 可能重複: #include <iostream> struct A { static const int v = 1; }; int main() { A a; std::cout << decltype(a)::v << std::endl; } 將產生下一個編譯錯誤:: C++0x decltype and the scope

    3熱度

    1回答

    這是我的絕招: template<typename F, typename TArg> auto get_return_value(F * f = NULL, TArg * arg = NULL) -> decltype((*f)(*arg)); 使用的實例: template<typename F, typename T> decltype(get_return_value<F