Consider
// https://godbolt.org/z/z5M9b9jzx
#include <memory>
#include <cassert>
struct B {};
struct D : B {};
int main() {
std::shared_ptr<B> b = std::make_shared<D>();
auto d = static_pointer_cast<D>(b);
assert(d);
}
I'd've expected the unqualified call to static_pointer_cast
to resolve to std::static_pointer_cast
, because b
, being a std::shared_ptr
, should bring namespace std
in using ADL.
Why doesn't it? I need to write std::shared_pointer_cast
explicitly to make it work.
<D>
, breaks ADL unless a compiler already knows that it's a template. – Lambertoidentifier <
which looks awfully like the beginningx < 2
. So it's grammatically difficult unlikeidentifier (args)
which can only be a function call or anoperator()(args)
call ifidentifier
designates an object or a "functional cast"/construction of a temporary [both are essentially the same concept through different syntactic constructs:std::string("")
is a cast (explicit type conversion) butstd::string()
is not] ifidentifier
designates a type. – Hydropic