जीसीसी (5.3) & क्लैंग (3.8) दावा करते हैं कि test
में पहली पंक्ति खराब है, लेकिन दूसरा ठीक है। एमएसवीसी (2015.2) कहता है, दोनों अमान्य हैं।constexpr टेम्पलेट तर्क अजीबता
template< typename N, typename T >
void f(N n, T t) { std::get<n>(t); }
void test() {
std::get< std::integral_constant< size_t, 0 >() >(std::make_tuple(123)); // not ok
f(std::integral_constant< size_t, 0 >(), std::make_tuple(123)); // ok for gcc, clang, but not msvc
}
मानक के अनुसार, वास्तव में क्या अंतर है? क्या यह कोड शुरू करने के लिए कानूनी है? पहली पंक्ति के लिए
बजना त्रुटि:
In file included from main.cpp:2:
/usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../include/c++/5.3.0/tuple:874:34: error: no matching function for call to '__get_helper2'
{ return std::forward<_Tp&&>(std::__get_helper2<_Tp>(__t)); }
^~~~~~~~~~~~~~~~~~~~~~~
main.cpp:10:10: note: in instantiation of function template specialization 'std::get<std::integral_constant<unsigned long, 0>(), int>' requested here
std::get<std::integral_constant<size_t, 0>()>(std::make_tuple(123)); // not ok
^
/usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../include/c++/5.3.0/tuple:856:5: note: candidate template ignored: could not match '_Tuple_impl' against 'tuple'
__get_helper2(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
^
/usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../include/c++/5.3.0/tuple:861:5: note: candidate template ignored: could not match '_Tuple_impl' against 'tuple'
__get_helper2(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
^
1 error generated.
जीसीसी त्रुटि:
In file included from main.cpp:2:0:
/usr/local/include/c++/5.3.0/tuple: In instantiation of 'constexpr _Tp&& std::get(std::tuple<_Elements ...>&&) [with _Tp = std::integral_constant<long unsigned int, 0ul>(); _Types = {int}]':
main.cpp:10:75: required from here
/usr/local/include/c++/5.3.0/tuple:874:57: error: no matching function for call to '__get_helper2(std::tuple<int>&)'
{ return std::forward<_Tp&&>(std::__get_helper2<_Tp>(__t)); }
^
/usr/local/include/c++/5.3.0/tuple:856:5: note: candidate: template<class _Head, long unsigned int __i, class ... _Tail> constexpr _Head& std::__get_helper2(std::_Tuple_impl<__i, _Head, _Tail ...>&)
__get_helper2(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
^
/usr/local/include/c++/5.3.0/tuple:856:5: note: template argument deduction/substitution failed:
/usr/local/include/c++/5.3.0/tuple:874:57: note: mismatched types 'std::integral_constant<long unsigned int, 0ul>()' and 'int'
{ return std::forward<_Tp&&>(std::__get_helper2<_Tp>(__t)); }
^
/usr/local/include/c++/5.3.0/tuple:874:57: note: 'std::tuple<int>' is not derived from 'std::_Tuple_impl<__i, std::integral_constant<long unsigned int, 0ul>(), _Tail ...>'
/usr/local/include/c++/5.3.0/tuple:861:5: note: candidate: template<class _Head, long unsigned int __i, class ... _Tail> constexpr const _Head& std::__get_helper2(const std::_Tuple_impl<__i, _Head, _Tail ...>&)
__get_helper2(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
^
/usr/local/include/c++/5.3.0/tuple:861:5: note: template argument deduction/substitution failed:
/usr/local/include/c++/5.3.0/tuple:874:57: note: mismatched types 'std::integral_constant<long unsigned int, 0ul>()' and 'int'
{ return std::forward<_Tp&&>(std::__get_helper2<_Tp>(__t)); }
^
/usr/local/include/c++/5.3.0/tuple:874:57: note: 'std::tuple<int>' is not derived from 'const std::_Tuple_impl<__i, std::integral_constant<long unsigned int, 0ul>(), _Tail ...>'
क्या आप कृपया हमें बता सकते हैं कि आपको कौन सी त्रुटियां मिलती हैं? –
मैं यहाँ टेक्स्ट की दीवारों को पोस्ट करने में बहुत सहज नहीं हूं, लेकिन यहां इसकी जानकारी है। एमएसवीसी के तहत दूसरी पंक्ति: "'std :: get': कोई मिलान ओवरलोडेड फ़ंक्शन नहीं मिला"। पहली पंक्ति: समान प्रकार के साथ सामान्य मम्बो-जंबो के सभी प्रकार 'std :: tuple' के आंतरिक संकेतों को इंगित करते हैं। – vpozdyayev
@vpozdyayev त्रुटियां बहुत मदद करती हैं - यह त्रुटि संदेश है जिसने मुझे यह समझने के लिए प्रेरित किया कि समस्या क्या थी। यह सिर्फ मम्बो-जंबो नहीं है। – Barry