निम्नलिखित कोड पर विचार करें:कटौती गाइड और variadic टेम्पलेट्स
#include <tuple>
#include <iostream>
template <class T>
struct custom_wrapper
{
template <class Arg>
custom_wrapper(Arg arg): data(arg) {}
T data;
};
template <class Arg>
custom_wrapper(Arg arg) -> custom_wrapper<Arg>;
template <class... T>
struct custom_tuple
{
template <class... Args>
custom_tuple(Args... args): data(args...) {}
std::tuple<T...> data;
};
template <class... Args>
custom_tuple(Args... args) -> custom_tuple<Args...>;
int main(int argc, char* argv[])
{
custom_wrapper<int> w1(42); // OK
custom_wrapper w2(42); // OK
custom_tuple<int> t1(42); // OK
custom_tuple t2(42); // Fails
return 0;
}
लाइन है कि जी ++ 7 के तहत निम्न त्रुटि लौटने में विफल रहता है:
variadic_deduction_guide.cpp: In instantiation of 'custom_tuple<T>::custom_tuple(Args ...) [with Args = {int}; T = {}]':
variadic_deduction_guide.cpp:31:23: required from here
variadic_deduction_guide.cpp:19:45: error: no matching function for call to 'std::tuple<>::tuple(int&)'
custom_tuple(Args... args): data(args...) {}
सामान्य है कि है या कि एक संकलक बग है ?
ओएम के कोड पर हम्म, जीसीसी और क्लैंग ट्रंक असहमत हैं, और मैं वास्तव में यहां आश्वस्त नहीं हूं। सबसे पहले, 'टी'" पीछे "है? (यह एक बदतर परिभाषित शब्द है।) दूसरा, क्या आप प्रदर्शन कर सकते हैं कि कन्स्ट्रक्शन कटौती मार्गदर्शिका से अधिक विशिष्ट कैसे है? –
@ टी.सी. लेकिन कटौती-गाइड के साथ काम कर क्लैंग को देखने के लिए अच्छा लगा! यह बहुत हाल ही में होना चाहिए। – Barry
यहां संदर्भ एक फंक्शन कॉल है, इसलिए ["आंशिक क्रम \ \ के लिए उपयोग किए जाने वाले प्रकार उन फ़ंक्शन पैरामीटर प्रकार हैं जिनके लिए फ़ंक्शन कॉल में तर्क हैं"] (https://timsong-cpp.github.io/cppwp /temp.deduct.partial#3.1)। और आंशिक क्रमिक उद्देश्यों के लिए, ["एक टेम्पलेट पैरामीटर एक मूल्य के बिना रह सकता है बशर्ते इसे आंशिक क्रम के लिए उपयोग किए जाने वाले प्रकारों में उपयोग नहीं किया जाता है"] (https://timsong-cpp.github.io/cppwp/temp.deduct। आंशिक # 12), और 'टी ...' नहीं है। तो वास्तव में एक दूसरे से कैसे अधिक विशिष्ट है? कटौती में कौन सी दिशा विफल होती है, और कैसे? –