I have just read Is declval<T>() the same as (*(T*)nullptr)? and just realized that I haven't heard of the (*(T*)nullptr)
trick before. If I analyze that snippet, it doesn't give me too much information, beside that (quoting the answer)
you can get an instance of T in a decltype without needing to worry about T's constructor
and also the example found there is just very trivial:
struct B { A a; }; typedef decltype((*(B*)nullptr).a) T1;
so, can please someone explain to me what this (*(T*)nullptr)
trick is and why (and how) would I want to use it (beside of the example above)?
Edit: decltype(B::a)
has the same meaning (https://gcc.godbolt.org/z/Pvjjza) so why overcomplicate it like this? Are there any historical meanings to the appearance of this trick (such as some compiler not supporting it or anything else more useful?)