decltype

    2熱度

    2回答

    是否可以使用decltype和\或std :: remove_reference調用析構函數(不使用操作符刪除)?以下是一個示例: #include <iostream> #include <type_traits> using namespace std; class Test { public: Test() {} virtual ~Test() {}

    3熱度

    3回答

    當我聲明一個類靜態方法時,是否可以使用decltype(或以任何其他類似的樣式)引用當前類?例如, class AAA { static AAA const make(); }; 我想使這樣的事情。 class AAA { static decltype(*this) const make(); // Not working because there's no

    0熱度

    1回答

    考慮下面的代碼: template <class Crtp> struct Base { const float& get(const short int i) const {return std::get<0>(tuple);} const double& get(const int i) const {return std::get<1>(tuple);} c

    1熱度

    1回答

    我實現一個簡單的曲線函數的返回類型: template <typename T> typename T::return_type ProfilerRun(T&& func, const std::string& routine_name = "unknown") { using std::chrono::duration_cast; using std::chrono::m

    4熱度

    2回答

    有什麼方法可以在C++宏中評估decltype?我的主要動機是創建一個能夠確定this類型並將其轉換爲字符串的宏。 如果無法使用decltype還有什麼其他方式在類聲明中使用的宏可以將類的類型作爲字符串?

    17熱度

    2回答

    如果函數模板返回decltype(auto)(或使用auto的另一個類型說明符),但返回語句不合格,那麼SFINAE的結果是什麼? return聲明是否被認爲是函數簽名的直接上下文? N3690草案中沒有任何內容似乎需要這樣做。默認情況下,我猜SFINAE不適用。 這似乎是不幸的,因爲你可以寫一個函數來轉發到另一個函數,但是你不能在寫代碼的時候使它的存在有條件的在委託上。此外,由於this不能在函

    1熱度

    1回答

    我正在嘗試在標題中描述的事情。 template <class T> void foo(const Foo* f) // this is general case template { } // this should work only if T has static variable named _Foo with type const Foo* template <class

    3熱度

    1回答

    快速的問題。如果我有一個功能簽名像 template <typename T, typename ItType> ItType binarySearch (T mid, ItType first, ItType last); 是否有無論如何做下面的事情?我知道這個語法不正確,但你明白了,因爲我可以做一個類似於常規函數的decltype,見下文。編譯器在編譯時知道ItType的類型,所以它不應

    3熱度

    1回答

    我想寫一個模板類,它可能會或可能不會定義一個特定的成員函數,具體取決於它的模板參數類型。此外,此成員函數的返回類型取決於模板參數成員的返回類型(如果已定義)。 下面是我的代碼小例子 #include <iostream> #include <type_traits> template <typename T> struct has_foo_int { private: temp

    2熱度

    3回答

    的值在C++ 11返回類型爲有實施sqrt函數,對於正的和負double輸入值的工作原理的方法嗎?如果輸入是負值,我希望返回類型爲std::complex<double>,如果是正值,我想返回類型爲double。我意識到簡單的解決方案是總是返回std::complex<double>,但這不是我所期待的。 下面我有我的第一次嘗試的例子,但是這不會編譯由於a在返回類型存在: inline declt