문제점이 this과 매우 비슷합니다.조건부 noexcept 및 과부하와 일치하지 않음
즉, noexcept
인 경우 noexcept
인 magic
메서드가 있습니다.
이상한 일이 "다른 방법은"두 과부하를 가지고 있으며, 컴파일러 magic
noexcept
-ness을 결정하는 제 오버를 선택한다. magic
가 나중에 호출 될 때
는 그러나 첫 과부하라고하지만, magic
의 noexcept
-ness은 동일하게 유지!
여기에 내가 이해부터 wandbox link
입니다 :이 시점에서 컴파일러에 의해 알려져 있지 user_method(dummy2)
때문에 다시
adl_caller(..., priority_tag<0>) noexcept
에 떨어질
noexcept(magic(dummy2{}))
전화noexcept(noexcept(adl_caller(...))
.
하지만 충분히 좋지 만, user_method(dummy2)
은 3 줄을 어떻게 호출합니까? 표준이 의도 한 것입니까?
죄송합니다. 충분히 명확하지 않으면 죄송합니다.
#include <iostream>
template <unsigned N> struct priority_tag : priority_tag<N - 1> {};
template <> struct priority_tag<0> {};
template <typename T>
auto adl_caller(T t, priority_tag<1>) noexcept(noexcept(user_method(t)))
-> decltype(user_method(t)) {
std::cout << "first adl_caller overload" << std::endl;
user_method(t);
}
// tricky noexcept ...
template <typename T> void adl_caller(T, priority_tag<0>) noexcept {
std::cout << "second adl_caller overload" << std::endl;
}
template <typename T>
void magic(T t) noexcept(noexcept(adl_caller(t, priority_tag<1>{}))) {
adl_caller(t, priority_tag<1>{});
}
struct dummy {};
struct dummy2 {};
// un-commenting this line makes the above call to cout print '0'
// void user_method(dummy2);
void user_method(dummy)
{
// user_method(dummy2) is declared after this point
// this line prints '1', since magic falls back to the second adl_caller overload
std::cout << "noexcept?: " << noexcept(magic(dummy2{})) << std::endl;
std::cout << "dummy method called" << std::endl;
// however, the first adl_caller overload is called here ...
magic(dummy2{});
}
void user_method(dummy2)
{
std::cout << "dummy2 method called" << std::endl;
}
int main()
{
magic(dummy{});
}
나는이 단락의 일부분을 이해한다고 생각하지만, 나에게 너무 애매하다. 내 예제에는 하나의 TU 만 있고 외부 링키지 함수는 없습니다. 마지막 단락은 연결된 코드와 어떤 관련이 있습니까? 제가 정확하게 이해한다면, '마법'방법은 첫 단락에 연결되어 있습니다, 그러나 나는 정확한 이유를 파악하는 데 약간의 어려움이 있습니다. 표준 발췌에 대해 감사드립니다. – Dante