decltype & auto return types
Në shqip përdoret i njëjti emër.
ShpjegimiSQ
decltype(x) të jep tipin e një shprehjeje pa e llogaritur — i dobishëm në template. Funksionet mund të shkruhen edhe me tipin e kthimit në fund: auto mblidh(A a, B b) -> decltype(a + b).
EnglishEN
decltype(x) gives you an expression's type without evaluating it — useful in templates. Functions can also put the return type at the end: auto add(A a, B b) -> decltype(a + b).
Si ta mendosh
Si të pyesësh „çfarë lloji do të dalë?“ pa e gatuar gjellën.
Lexoje në anglisht
Like asking “what kind of dish will this be?” without cooking it.
Shembull kodicpp
int x = 5;
decltype(x) y = 10; // int
template <class A, class B> auto mblidh(A a, B b) -> decltype(a + b) { return a + b; }