decltype

    2熱度

    1回答

    演繹類型時,我聲明如下常量: const auto val = someFun(); 現在我想用同一類型的「VAL」的,但沒有固定規範的另一個變量。 decltype(val) nonConstVal = someOtherFun(); // Modify nonConstVal, this is error when using decltype 當前decltype保持常量。如何去除

    1熱度

    1回答

    我已閱讀this問題,它對我沒有幫助。 我的問題是:爲set使用如下的密鑰類型的比較函數時,爲什麼會出現運行時錯誤? multiset<Phone, decltype(comp)*> phones { Phone(911), Phone(112) }; //^^^^^^^^^^^^^^^ 在VC2013它給了我這個上面的代碼: Unhandled exception at 0x

    2熱度

    1回答

    我在閱讀Scott Meyers的Effective Modern C++我試圖在我的機器上爲推導類型章節提供的示例。 他提供了這樣的功能: template <typename Container, typename Index> auto decltype_test_1(Container& c, Index i) -> decltype(c[i]) { return c[i];

    9熱度

    1回答

    我最近看到一些基於SFINAE代碼看起來像這樣: template <typename T> auto test(T &myclass) -> decltype(myclass.f(), void()) { // do something here, don't return anything (void) } 基本上上面的函數使用SFINAE拒絕沒有f()作爲一個成員函數T類

    2熱度

    1回答

    對於具有表達式模板的類,在重載運算符的返回類型演繹期間,我偶然發現了以下錯誤。下面的例子說明了錯誤: template < typename T > struct A_Number { T x; }; // TAG1 template < typename T > A_Number<T> operator+(const A_Number<T> &a, const A_Nu

    6熱度

    1回答

    今天我看到一些像這樣的代碼: int a = 0; const decltype((a)) x = 10; // Error const int b = 0; decltype ((b)) y = 42; // Correct 我可以看到爲什麼正確的代碼是正確的,但我不明白爲什麼不正確的代碼不正確。 我測試了一下,發現它有點奇怪。 const decltype((a)) x = 10;

    3熱度

    1回答

    我有以下的重載函數: template<size_t N, typename T> auto get(const T & _t) -> decltype(std::get<...>(_t)) { ... } template<size_t N, typename T> auto get(T & _t) -> decltype(std::get<...>(_t)) {

    2熱度

    1回答

    的我有以下代碼: struct A { const string name; A(string name) :name(name) {} }; struct Parent { public: const decltype(make_tuple(A("AA"))) children{ make_tuple(A("AA")) }; Parent(

    5熱度

    1回答

    有時候可能需要聲明x與y的類型相同。使用vals類型推斷可以很好地處理這個問題,但這在其他一些領域不起作用,如with function types。 對於有一些C++經驗的程序員來說,這似乎是一個明顯的解決方案,那就是decltype。目前的斯卡拉似乎沒有這樣的設施。 到鏈接問題的答案告訴: 因爲類型不是一等公民 我不得不承認,我不明白這一點。我不認爲類型是C++中的第一類公民,但它仍然可以有d

    3熱度

    4回答

    我想要實例 template<typename T> void foo( T& t, SomeType some_parameter, AnotherType another_parameter, EtcType yet_another_parameter, AsYouCanTell this_is_a_very_long_signature);