c++ - template operator -> -


is there way conviniently call template operator-> ? cool have such possibility in classes variant

for example: (thats example)

struct base_t {    template<class t>    t* operator->()    {       return reinterpret_cast<t*>(this);    } };  int main(int argc, char* argv[]) {    base_t x;    x.operator-><std::pair<int,int>>()->first; //works, inconvenient    x<std::pair<int,int>>->first; // not work    x-><std::pair<int,int>>first; //does not work     return 0; } 

i need proofs =)

no, it's not real, how it's not real too

struct base_t {    template<class t>    t operator () ()    {       return t();    } };  int main() {    base_t x;    x.operator ()<int>(); // works    x.()<int>(); // not works } 

expression x->m interpreted (x.operator->())->m class object x of type t if t::operator->() exists , if operator selected best match function overload resolution mechanism

postfix-expression -> templateopt id-expression

postfix-expression -> pseudo-destructor-name

so, syntax x-><t> incorrect.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -