advertisement
Login | Register   
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   TIP BANK
Browse DevX
Partners & Affiliates
advertisement
advertisement
advertisement
 Print Print
 

Easier C++: An Introduction to Concepts

C++0x concepts bring the full power of the Generic Programming paradigm to C++, making templates more expressive, easier to write, and easier to use. Spectacularly poor template error messages are a thing of the past! 


advertisement
very C++ programmer has had one of those days: A simple use of a template library turns into a nightmare, with pages upon pages of error messages streaming out of the compiler. Somewhere in that proverbial haystack are the clues you will need to determine exactly what went wrong—an error about a missing + operator here, an incompatible type assignment there—but you know you are in for a long search through the grisly internals of the template library, or a visit from your local C++ template guru.

This article is not about C++ template error messages, but they are indicative of a far more general problem with the C++ template system. Most errors in the use of templates come from a misunderstanding between the author of the template and the user of the template. The author of the template expects the user's type to provide some specific set of operations, say, a + operator for addition and a copy assignment operator, which I'll refer to as the template requirements. When the user provides a type with the appropriate operations, i.e., the type satisfies the template requirements, everything works. However, when the user's type is missing some operations, the compiler reports the error as soon as the template tries to use that operation, which is often deep in the implementation of the template library. Thus, the template requirements are effectively a contract between the template author and user, and debugging a template error message is the act of trying to determine who broke the contract—and how.


It's quick, easy and you get access to all the articles on DevX.
This registration/login is to allow you to read articles on devx.com.
Already a member?



DevX is a division of Internet.com.
© Copyright 2010 Internet.com. All Rights Reserved. Legal Notices
advertisement