Presentation is loading. Please wait.

Presentation is loading. Please wait.

Generic Programming and Library Design Brian Bartman

Similar presentations


Presentation on theme: "Generic Programming and Library Design Brian Bartman"— 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 using namespace std; int main() { list 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 x) -> list ::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 myList; The above is valid C++0x and will yield a list of doubles.


Download ppt "Generic Programming and Library Design Brian Bartman"

Similar presentations


Ads by Google