मैं कार्यात्मक हेडर फ़ंक्शन constexpr
बनाने के प्रस्ताव पर काम कर रहा हूं। (std::invoke
, std::reference_wrapper
, std::bind
, std::mem_fn
, std::not_fn
)constexpr फ़ंक्शन टेम्पलेट्स तत्काल कब हैं?
मैंने सीखा है क्योंकि constexpr
कार्यों बेसब्री से instantiated कर रहे हैं कि constexpr
जोड़ने मौजूदा कोड तोड़ सकते हैं।
template<class T>
int f(T){
return T::not_existing_member;
}
template<class T>
constexpr int g(T){
return T::not_existing_member;
}
int main(){
decltype(f(0)) a; // Well-formed
decltype(g(0)) b; // Ill-formed if the function body is instantiated
}
जीसीसी इस कोड को संकलित करता है, क्लैंग नहीं करता है। मैं my proposal में वर्णन करता हूं कि आप std::bind
के उदाहरण का उपयोग करके ओवरलोड के साथ उत्सुक तात्कालिकता को कैसे नियंत्रित कर सकते हैं।
आप मुझे बता सकते मानक में यह वर्णन किया गया है, जहां जब एक संकलक करना पड़ता है और जब यह करने की अनुमति है दृष्टांत एक समारोह टेम्पलेट?
template<class T>
struct Foo{
constexpr int f(){
return 0;
}
constexpr int f()const{
return T::not_existing_member;
}
};
int main(){
/* constexpr */ Foo<int> foo;
foo.f(); // Ill-formed with, Well-formed without constexpr by the standard?
}
दोनों जीसीसी और बजना कोड संकलन करता है, तो foo
नहीं है:
दरअसल मैं कार्यान्वयन परिभाषित करता है, तो निम्न उदाहरण में जीसीसी और बजना के समान व्यवहार मानक द्वारा लागू या है जानना चाहता हूँ constexpr
और दोनों इसे अस्वीकार करते हैं यदि यह है।
आह हाँ। उदाहरण # 2 के बारे में तर्क में मुझे एक त्रुटि हुई। 'फू' होने के साथ'constexpr 'भी यह निश्चित रूप से'const'' बन जाता है और इसलिए'const 'अधिभार सीधे कहा जाता है। आपका बहुत बहुत धन्यवाद! –