find_type
कैसे पता चलता है कि फ़ंक्शन typemap
है?
वह जो तर्क प्राप्त करता है वह उस नामस्थान से नहीं है, यह std
नामस्थान से है!यह एडीएल केस क्यों काम कर रहा है?
#include <type_traits>
#include <memory>
namespace lib {
template<typename T>
struct find_type {
using type = decltype(typemap(std::declval<T>()));
};
}
namespace test {
struct Test {};
auto typemap(std::unique_ptr<Test>) -> int;
}
static_assert(std::is_same<int, lib::find_type<std::unique_ptr<test::Test>>::type>::value, "");
यह कोड कैसे काम कर सकता है? इस नियम को अनुमति देने वाला नियम क्या है?
मैंने इसे जीसीसी 6.3 और क्लैंग 3.9.1 के साथ परीक्षण किया।
संरचना 'find_type' से टेम्पलेट पैरामीटर' टी' का पैरामीटर प्रकार 'std :: unique_ptr' है। 'std :: unique_ptr' एडीएल के लिए 'test :: test' टेम्पलेट पैरामीटर मानता है, और इस प्रकार,' test' NS में' typemap' फ़ंक्शन पाता है –
SebNag