1 / 8

Generic Programming and Library Design

Generic Programming and Library Design. Brian Bartman bbartman@kent.edu. Introduction to C++0X. C++0X is the newest standard of C++. It adds many new features and extensions of the language. Some of the new features are: Type inference Lambda functions Variadic Templates.

dalila
Télécharger la présentation

Generic Programming and Library Design

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Generic Programming and Library Design Brian Bartman bbartman@kent.edu

  2. Introduction to C++0X • C++0X is the newest standard of C++. • It adds many new features and extensions of the language. • Some of the new features are: • Type inference • Lambda functions • Variadic Templates

  3. Type Inference • Type inference refers to the automatic deduction of the type of an expression in a programming language. • Many programming languages have type inference, for example C# and java. • Type inference in C# allows for the user to specify a variable a var and have the compiler deduce what type the variable actually is.

  4. Type Inference in C++0X • New and re-tooled keywords used for type inference: • auto • decltype()

  5. The auto keyword:Variable type inference • Auto is used to deduce the type of a variable based on the return type of a function being assigned to it. • Example: #include <list> #include <iostream> using namespace std; int main() { list<int> myList; for(auto x = myList.begin(); x != myList.end(); ++x) cout << *x; }

  6. The auto keyword:Function return type inference • Late binding function return types. • Allows for the return type of a function to be declared after the function is declared instead of before like usual. auto foo(list<int> x) -> list<int>::iterator; • There is a special case which allows for one line functions to not to have to give a return type other then auto. auto begin() const { return iterator(memPtr); }

  7. The decltype keyword:Basic Description • decltype is a new keyword added with C++0X. • It is a built in function of the compiler, which is completely evaluated at compile time and yields a type from a given expression. • Because decltype is a built-in function there is no need to include any header files.

  8. The decltype keyword:Usage Examples • The main usage examples of decltype are with functionality of C++ which requires a type. For example template parameters. unsigned int x; double y; list<decltype(x + y)> myList; The above is valid C++0x and will yield a list of doubles.

More Related