How does decltype work?

Is it calculated only at compile time? Does this mean what is the type of expression or its type of return and just replaces it? That is, does it work like macro preprocessing? Also, if I wrote this:

std::map<std::string, int> m;
decltype(m.cbegin()) i;

Will it be called cbeginand I will pay for some performance here?

EDIT: I already know what I can write decltype(m)::const_iterator i;

+4
source share
2 answers

decltypeStrictly works at compile time. So you can use it with code that will dereference iterators end, or use

decltype(sqrt(-1.))

Absolutely no execution penalty associated with this is simply executed.


, :

decltype , . , decltype(m)::const_iterator i; , - .

+3

decltype (m):: const_iterator i;

!

std::map<std::string, int> m;
decltype(m)::const_iterator i; // same as std::map<std::string, int>::const_iterator

GNU ++ well.

+1

Source: https://habr.com/ru/post/1626954/


All Articles