Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Clean Up Function Syntax Mess with decltype

The funky syntax of a function's return type isn't just unreadable in many cases—it's also a common source of maintenance problems. However, with the new decltype operator your functions will look much cleaner and easier to maintain.


advertisement

he auto keyword presented here is related to another C++09 proposal: the decltype operator. decltype(e) retrieves the type of the expression e. By combining decltype and auto, you can simplify complex function declarations and reduce maintenance costs. The following sections will show you how to use decltypeto make your functions sing.


Your function consists of a simple return statement. Alas, the manual declaration of a complex return type makes your code brittle and illegible.


Use the decltypeoperator to extract the return type from an expression instead of spelling it out explicitly.





Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap