我很困惑:在升級到GCC 6(RC1)後,一些使用std::common_type
失敗的模板代碼。我嘗試了叮噹,那也失敗了...所以我一定是做錯了!std :: common_type與type_info的引用
該代碼相當於:
#include <type_traits>
#include <typeinfo>
using namespace std;
// common_type of two const type_info& is ok (compiles ok)
common_type<const type_info&, const type_info&>::type func1();
// common_type of three type_info& is bad...(fails to compile)
common_type<const type_info&, const type_info&, const type_info&>::type func2();
// common_type of two const int& is ok
common_type<const int&, const int&>::type func3();
// common_type of three const int& is ok too!
common_type<const int&, const int&, const int&>::type func4();
第二common_type
與三個參數類型的std::type_info const &
無法編譯。鏗鏘暗示暗示我使用了雙參數std::common_type
,但這是在模板擴展中,我無法控制輸入!
這似乎很奇怪:爲什麼const type_info&
與3失敗,但沒有任何其他看似等效類型失敗?
在這裏看到:https://godbolt.org/g/Ob4y0x
'common_type'現在衰變,並導致「有趣」的事情。 –
一些twitter引用指出我這樣一個事實:'std :: common_type'返回Ts的'std :: decay' ......這對我的用例來說是非常煩人的,但是解釋了上面的錯誤。 –
@MattG:你可以隨時用'common_type_t ...>替換'common_type_t '',所以它不應該超級煩人。 –