Generic Programming and Library Design Brian Bartman

Slides:



Advertisements
Similar presentations
Introduction to C++ An object-oriented language Unit - 01.
Advertisements

Yaser Zhian Dead Mage IGDI, Workshop 10, May 30 th -31 st, 2013.
1 Linked Lists III Template Chapter 3. 2 Objectives You will be able to: Write a generic list class as a C++ template. Use the template in a test program.
Brown Bag #2 Advanced C++. Topics  Templates  Standard Template Library (STL)  Pointers and Smart Pointers  Exceptions  Lambda Expressions  Tips.
Introduction to C++ Programming. Brief Facts About C++ Evolved from C Designed and implemented by Bjarne Stroustrup at the Bell Labs in the early 1980s.
Functions Function: The strength of C language is to define and use function. The strength of C language is that C function are easy to define and use.
Or: The Ampersand Recovery && Reinvestment Act of 2010 Stephan T. Lavavej Visual C++ Libraries Developer 1Version April 28, 2009.
1 Lecture 16:User-Definded function I Introduction to Computer Science Spring 2006.
Chapter 6 Advanced Function Features Pass by Value Pass by Reference Const parameters Overloaded functions.
Template. 2 Using templates, it is possible to create generic functions and classes. In a generic function or class, the type of data upon which the function.
Introduction to Programming in C++ John Galletly.
Review What is a virtual function? What can be achieved with virtual functions? How to define a pure virtual function? What is an abstract class? Can a.
March 25, 2014CS410 – Software Engineering Lecture #12: Advanced C++ I 1 Alumni Party The Alumni Party will take place on Tuesday, May 13 It would be great.
C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
True or false A variable of type char can hold the value 301. ( F )
1 Lecture-4 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Announcements Quiz 1 Next Week. int : Integer Range of Typically -32,768 to 32,767 (machine and compiler dependent) float : Real Number (i.e., integer.
Rossella Lau Lecture 1, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 1: Introduction What this course is about:
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Chapter 16 Templates. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives  Function Templates  Syntax, defining 
Abstract Data Types and Encapsulation Concepts
 2007 Pearson Education, Inc. All rights reserved C++ as a Better C; Introducing Object Technology.
Templates Overload function: define more than one function With same function name Different parameter type Different type Different number of parameter.
Programming Introduction to C++.
Introduction to C++ Programming
C++ Functions. 2 Agenda What is a function? What is a function? Types of C++ functions: Types of C++ functions: Standard functions Standard functions.
C# Tutorial From C++ to C#. Some useful links Msdn C# us/library/kx37x362.aspxhttp://msdn.microsoft.com/en- us/library/kx37x362.aspx.
OOP Languages: Java vs C++
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
Introduction to C++ // Program description #include directives int main() { constant declarations variable declarations executable statements return.
Rossella Lau Lecture 1, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 1: Introduction What this course is about:
COMPUTER PROGRAMMING. Functions What is a function? A function is a group of statements that is executed when it is called from some point of the program.
Lecture #5 Introduction to C++
1 C++ Syntax and Semantics, and the Program Development Process.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Week 1 Algorithmization and Programming Languages.
Beginning C++ Through Game Programming, Second Edition
C++ Lecture 1 Friday, 4 July History of C++ l Built on top of C l C was developed in early 70s from B and BCPL l Object oriented programming paradigm.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
March 2006 Copyright, 2006 Oxford Consulting, Ltd C++ Templates Templates F Part of the ongoing development of the C++ language F Integral part.
C++ / G4MICE Course Session 2 Basic C++ types. Control and Looping Functions in C Function/method signatures and scope.
1 What is a Named Constant? A named constant is a location in memory that we can refer to by an identifier, and in which a data value that cannot be changed.
CSE 332: C++ pointers, arrays, and references Overview of Pointers and References Often need to refer to another object –Without making a copy of the object.
CSC1201: Programming Language 2 1 Functions. 2 Function declaration: return_type FuncName( Type arg1, Type arg2,….. Type argN) { function body } A program.
CSIS 123A Lecture 7 Static variables, destructors, & namespaces.
CSCE Introduction to Program Design and Concepts J. Michael Moore Spring 2015 Set 6: Miscellaneous 1 Based on slides created by Bjarne Stroustrup.
Intro. to Computer Programming Eng. Nehal A. Mohamed Spring Semester-2016.
FUNCTIONS (C) KHAERONI, M.SI. OBJECTIVE After this topic, students will be able to understand basic concept of user defined function in C++ to declare.
History C++11 : First ContactE. Conteslide 2 C First international standard of the C++ language. Published as ISO/IE C 14882:1998 C
MAITRAYEE MUKERJI Object Oriented Programming in C++
Introduction to C++ programming Recap- session 1 Structure of C++ program Keywords Operators – Arithmetic – Relational – Logical Data types Classes and.
C++ Lesson 1.
Chapter 2 Introduction to C++ Programming
C++ Templates.
Pointers and Pointer-Based Strings
Mr. Shaikh Amjad R. Asst. Prof in Dept. of Computer Sci. Mrs. K. S
A brief look at some of the new features introduced to the language
Name: Rubaisha Rajpoot
Introduction to C++ Programming
Programming Introduction to C++.
Pointers and Pointer-Based Strings
Functions Imran Rashid CTO at ManiWeber Technologies.
C++ Programming Basics
CISC/CMPE320 - Prof. McLeod
C Language B. DHIVYA 17PCA140 II MCA.
SPL – PS1 Introduction to C++.
Data Types and Arithmetic in C
Presentation transcript:

Generic Programming and Library Design Brian Bartman

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

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.

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

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; }

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); }

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.

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.