auto map<deque<string>, vector<string>> mymap; for(auto iter = mymap.begin(); iter!= mymap.end(); ++iter) {
|
|
- Corey Allison
- 5 years ago
- Views:
Transcription
1
2
3
4 auto auto
5 auto How can we clean this up better? The auto keyword! map<deque<string>, vector<string>> mymap; for(auto iter = mymap.begin(); iter!= mymap.end(); ++iter) { } dosomething(*(iter).first, *(iter).second);
6 for for map<string, int> mymap; for(auto thing : mymap) { dosomething(thing.first, thing.second); } map<string, int> mymap; for(auto iter = mymap. begin(); iter!= mymap. end(); ++iter) { auto thing = *iter; dosomething(thing.first, thing.second); }
7 template <typename T> T min(t a, T b) { return (a < b)? a : b; }
8 int a = 3, b = 9; int c = min<int>(a, b); s I don t have a min<int> :( But I know how to make one! template <typename T> T min(t a, T b) { return (a < b)? a : b; } int min<int>(int a, int b) { return (a < b)? a : b; }
9
10 std::vector<int> v(10); auto mid = v.begin() + v.size()/2; std::deque<int> d(13); auto some_iter = d.begin() + 3;
11 std::vector<int> v(10); auto mid = v.begin() + v.size()/2; Sounds right! std::deque<int> d(13); auto some_iter = d.begin() + 3;
12 std::list std::list<int> mylist(10); auto some_iter = mylist.begin() + 3;
13 std::list std::list<int> mylist(10); auto some_iter = mylist.begin() + 3;
14 std::list std::list<int> mylist(10); auto some_iter = mylist.begin() + 3; What s going on here?
15
16 Input Output Forward Bidirectional Random Access
17 ==!= Input Output Forward Bidirectional Random Access
18 vector<int> v =... vector<int>::iterator itr = v.begin(); int val = *itr; Input Output Forward Bidirectional Random Access
19 vector<int> v =... vector<int>::iterator itr = v.begin(); *itr = 12; Input Output Forward Bidirectional Random Access
20 vector<int> v =... vector<int>::iterator itr = v.begin(); int val = *itr; int val2 = *itr; Input Output Forward Bidirectional Random Access
21 -- vector<int> v =... vector<int>::iterator itr = v.begin(); ++itr; int val = *itr; --itr; int val2 = *itr; Input Output Forward Bidirectional Random Access
22 + - vector<int> v =... vector<int>::iterator itr = v.begin(); int val = *itr; itr = itr + 3; int val2 = *itr; Input Output Forward Bidirectional Random Access
23
24 Algorithms Functors/Lambdas Iterators Adapters Allocators Containers
25 You are here! Algorithms Functors/Lambdas Iterators Adapters Allocators Containers
26
27
28 Basic Types
29 vector<int> map<string, int>
30 Containers Basic Types
31 vector> Can we perform operations on containers regardless of what the container is?
32
33 Iterators Containers Basic Types
34
35 Algorithms Iterators Containers Basic Types
36
37 .pro
38 std::copy std::copy vector<int> v {561, 1105, 1729, 2465}; vector<int> vcopy(v.size()); std::copy(v.begin(), v.end(), vcopy.begin());
39 std::copy v: vcopy:
40 std::copy v: vcopy:
41 std::copy v: vcopy:
42 std::copy v: vcopy:
43 std::copy v: vcopy:
44 std::copy vector<int> v {561, 1105, 1729, 2465}; vector<int> vcopy(v.size()); std::copy(v.begin(), v.end(), vcopy.begin());
45 std::copy vector<int> v {561, 1105, 1729, 2465}; vector<int> vcopy(v.size()); std::copy(v.begin(), v.end(), vcopy.begin());
46 std::copy vector<int> v {561, 1105, 1729, 2465}; vector<int> vcopy(2); std::copy(v.begin(), v.end(), vcopy.begin());
47 std::copy v: vcopy: 0 0
48 std::copy v: vcopy: 561 0
49 std::copy v: vcopy:
50 std::copy v: vcopy:
51 std::copy v: vcopy:
52 std::copy C++ has a solution!
53
54 This is where iterator adaptors come in.
55 * ++
56 std::ostream_iterator * ++ std::ostream_iterator std::ostream
57 std::ostream_iterator.pro
58 std::ostream_iterator std::ostream_iterator<int> itr(cout, ", ") *itr = 3; // prints 3 to console ++itr; *itr = 1729; // prints 1729 to console ++itr; *itr = 13; // prints 13 to console Output: 3, 1729, 13,
59 std::ostream_iterator
60 std::ostream_iterator
61 std::ostream_iterator
62 std::ostream_iterator std::vector<int> v{3, 1, 4, 1, 5}; std::copy(v.begin(), v.end(), std::ostream_iterator<int>(cout, ", "))
63
64 std::back_inserter
65 std::copy v: vcopy:
66
67 std::inserter std::back_inserter std::front_inserter). insert push_back push_front.
68 .pro
69 std::vector<int> v; // empty vec auto itr = std::back_inserter(v); *itr = 1729; // does v.push_back(1729) ++itr; *itr = 13; // does v.push_back(13) ++itr; *itr = 3; // does v.push_back(3) v look like this: {1729, 13, 3}
70 vector<int> v {561, 1105, 1729, 2465}; vector<int> vcopy(v.size()); std::copy(v.begin(), v.end(), vcopy.begin());
71 vector<int> v {561, 1105, 1729, 2465}; vector<int> vcopy(v.size()); std::copy(v.begin(), v.end(), vcopy.begin());
72 vector<int> v {561, 1105, 1729, 2465}; vector<int> vcopy; std::copy(v.begin(), v.end(), vcopy.begin());
73 vector<int> v {561, 1105, 1729, 2465}; vector<int> vcopy; Start with empty vector std::copy(v.begin(), v.end(), vcopy.begin());
74 vector<int> v {561, 1105, 1729, 2465}; vector<int> vcopy; std::copy(v.begin(), v.end(), vcopy.begin());
75 vector<int> v {561, 1105, 1729, 2465}; vector<int> vcopy; std::copy(v.begin(), v.end(), vcopy.begin());
76 vector<int> v {561, 1105, 1729, 2465}; vector<int> vcopy; std::copy(v.begin(), v.end(), std::back_inserter(vcopy));
77 std::copy v: vcopy:
78 std::copy v: vcopy: 561
79 std::copy v: vcopy:
80 std::copy v: vcopy:
81 std::copy v: vcopy:
82
83
84
Advanced Associative Containers. Ali Malik
Advanced Associative Containers Ali Malik malikali@stanford.edu Game Plan Recap Map Iterators Further Usage Multimap auto and Range Based for Recap Associative Containers Useful abstraction for associating
More informationAssociative Containers and Iterators. Ali Malik
Associative Containers and Iterators Ali Malik malikali@stanford.edu Game Plan Recap Associative Containers Iterators Map Iterators The auto keyword (maybe) Range-Based for Loops (maybe) Recap Structs
More information/ binary_search example #include <iostream> // std::cout #include <algorithm> // std::binary_search, std::sort #include <vector> // std::vector
Algorithm Searching Example find, search, binary search / binary_search example #include // std::cout #include // std::binary_search, std::sort #include // std::vector bool
More informationTemplate based set of collection classes STL collection types (container types)
STL Collection Types Template based set of collection classes STL collection types (container types) Sequences vector - collection of elements of type T list - doubly linked list, only sequential access
More informationWriting Generic Functions. Lecture 20 Hartmut Kaiser hkaiser/fall_2013/csc1254.html
Writing Generic Functions Lecture 20 Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/ hkaiser/fall_2013/csc1254.html Code Quality Programming Principle of the Day Minimize Coupling - Any section
More informationuse static size for this buffer
Software Design (C++) 4. Templates and standard library (STL) Juha Vihavainen University of Helsinki Overview Introduction to templates (generics) std::vector again templates: specialization by code generation
More informationSSE2034: System Software Experiment 3
SSE2034: System Software Experiment 3 Spring 2016 Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu STL Collection Types Template based set of collection
More informationCS11 Advanced C++ Spring 2018 Lecture 2
CS11 Advanced C++ Spring 2018 Lecture 2 Lab 2: Completing the Vector Last week, got the basic functionality of our Vector template working It is still missing some critical functionality Iterators are
More informationTHE STANDARD TEMPLATE LIBRARY (STL) Week 6 BITE 1513 Computer Game Programming
THE STANDARD TEMPLATE LIBRARY (STL) Week 6 BITE 1513 Computer Game Programming What the heck is STL???? Another hard to understand and lazy to implement stuff? Standard Template Library The standard template
More informationThe Standard Template Library. EECS 211 Winter 2018
The Standard Template Library EECS 211 Winter 2018 2 Problem: finding the maximum element of a vector A simple fixed-size vector struct: struct Int_vec int* data; size_t size; ; 3 Solution: max_int_vec
More informationType Aliases. Examples: using newtype = existingtype; // C++11 typedef existingtype newtype; // equivalent, still works
Type Aliases A name may be defined as a synonym for an existing type name. Traditionally, typedef is used for this purpose. In the new standard, an alias declaration can also be used C++11.Thetwoformsareequivalent.
More informationContainers in C++ and Java
Containers in C++ and Java 1 1. Which of the following statements is true? a) Equality on the basis of reference implies equality on the basis of content. b) Equality on the basis of content implies equality
More informationTDDD38 - Advanced programming in C++
TDDD38 - Advanced programming in C++ STL II Christoffer Holm Department of Computer and information science 1 Iterators 2 Associative Containers 3 Container Adaptors 4 Lambda Functions 1 Iterators 2 Associative
More informationStandard Template Library
Standard Template Library The standard template library (STL) contains CONTAINERS ALGORITHMS ITERATORS A container is a way that stored data is organized in memory, for example an array of elements. Algorithms
More information19. Dynamic Data Structures II
Different Memory Layout: Linked List 19. Dynamic Data Structures II Linked Lists, Vectors as Linked Lists No contiguous area of memory and no random access Each element points to its successor Insertion
More informationCopy Constructors & Destructors
Copy Constructors & Destructors 2-07-2013 Implementing a vector class local functions implicit constructors Destructors Copy Constructors Project #1: MiniMusicPlayer Quiz today 2/7/13 vectors and reading
More informationCS197c: Programming in C++
CS197c: Programming in C++ Lecture 2 Marc Cartright http://ciir.cs.umass.edu/~irmarc/cs197c/index.html Administration HW1 will be up this afternoon Written assignment Due in class next week See website
More informationSequential Containers. Ali Malik
Sequential Containers Ali Malik malikali@stanford.edu Game Plan Recap Overview of STL Sequence Containers std::vector std::deque Container Adapters Announcements Recap getline vs >> Bug favnum = fullname
More informationSequential Containers. Ali Malik
Sequential Containers Ali Malik malikali@stanford.edu Game Plan Recap Stream wrapup Overview of STL Sequence Containers std::vector std::deque Container Adapters Announcements Recap stringstream Sometimes
More informationOutline. Variables Automatic type inference. Generic programming. Generic programming. Templates Template compilation
Outline EDAF30 Programming in C++ 4. The standard library. Algorithms and containers. Sven Gestegård Robertz Computer Science, LTH 2018 1 Type inference 2 3 The standard library Algorithms Containers Sequences
More informationSTL Quick Reference for CS 241
STL Quick Reference for CS 241 Spring 2018 The purpose of this document is to provide basic information on those elements of the C++14 standard library we think are most likely to be needed in CS 241.
More informationFunction Templates. Consider the following function:
Function Templates Consider the following function: void swap (int& a, int& b) { int tmp = a; a = b; b = tmp; Swapping integers. This function let's you swap the contents of two integer variables. But
More informationTell compiler ValueType is a generic type. public: void push_back(const ValueType& elem); // rest of implementation }
template class StrVector { Tell compiler ValueType is a generic type. public: void push_back(const ValueType& elem); // rest of implementation } template class
More informationC++ 프로그래밍실습. Visual Studio Smart Computing Laboratory
C++ 프로그래밍실습 Visual Studio 2015 Templates & STL Contents Exercise Practice1 Templates & STL Practice 1-1 Template Classes #include using namespace std; template class Point { private:
More informationExceptions, Templates, and the STL
Exceptions, Templates, and the STL CSE100 Principles of Programming with C++, Fall 2018 (based off Chapter 16 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/
More informationGridKa School 2013: Effective Analysis C++ Standard Template Library
GridKa School 2013: Effective Analysis C++ Standard Template Library Introduction Jörg Meyer, Steinbuch Centre for Computing, Scientific Data Management KIT University of the State of Baden-Wuerttemberg
More informationby Pearson Education, Inc. All Rights Reserved. 2
An important part of every container is the type of iterator it supports. This determines which algorithms can be applied to the container. A vector supports random-access iterators i.e., all iterator
More informationContainer Notes. Di erent Kinds of Containers. Types Defined by Containers. C++11 Container Notes C++11
Di erent Kinds of Containers Container Notes A container is an object that stores other objects and has methods for accessing the elements. There are two fundamentally di erent kinds of containers: Sequences
More information19.1 The Standard Template Library
Chapter 19: The Template Library From a review of Effective STL : 50 Specific Ways to Improve Your Use of the Standard Template Library by ScottMeyers: It s hard to overestimate the importance of the Standard
More informationModern and Lucid C++ for Professional Programmers. Part 7 Standard Containers & Iterators. Department I - C Plus Plus
Department I - C Plus Plus Modern and Lucid C++ for Professional Programmers Part 7 Standard Containers & Iterators Prof. Peter Sommerlad / Thomas Corbat Rapperswil, 8.11.2017 HS2017 STL Containers: General
More informationArrays - Vectors. Arrays: ordered sequence of values of the same type. Structures: named components of various types
Arrays - Vectors Data Types Data Type: I. set of values II. set of operations over those values Example: Integer I. whole numbers, -32768 to 32767 II. +, -, *, /, %, ==,!=, , =,... Which operation
More informationTemplates and Vectors
Templates and Vectors 1 Generic Programming function templates class templates 2 the STL vector class a vector of strings enumerating elements with an iterator inserting and erasing 3 Writing our own vector
More informationCSCI-1200 Data Structures Spring 2018 Lecture 10 Vector Iterators & Linked Lists
CSCI-1200 Data Structures Spring 2018 Lecture 10 Vector Iterators & Linked Lists Review from Lecture 9 Explored a program to maintain a class enrollment list and an associated waiting list. Unfortunately,
More information6.096 Introduction to C++
MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Massachusetts Institute
More informationWe look back... #include <iostream> #include <vector>
165 6. C++ advanced (I) Repetition: vectors, pointers and iterators, range for, keyword auto, a class for vectors, subscript-operator, move-construction, iterators We look back... #include #include
More informationCSCI-1200 Data Structures Fall 2013 Lecture 9 Iterators & Lists
Review from Lecture 8 CSCI-1200 Data Structures Fall 2013 Lecture 9 Iterators & Lists Explored a program to maintain a class enrollment list and an associated waiting list. Unfortunately, erasing items
More informationStandard Template Library. Containers, Iterators, Algorithms. Sequence Containers. Containers
Standard Template Library The standard template library (STL) contains Containers Algorithms Iterators A container is a way that stored data is organized in memory, for example an array of elements. Algorithms
More informationExercise 6.2 A generic container class
Exercise 6.2 A generic container class The goal of this exercise is to write a class Array that mimics the behavior of a C++ array, but provides more intelligent memory management a) Start with the input
More informationCS 103 Unit 12 Slides
1 CS 103 Unit 12 Slides Standard Template Library Vectors & Deques Mark Redekopp 2 Templates We ve built a list to store integers But what if we want a list of double s or char s or other objects We would
More informationSTL: C++ Standard Library
STL: C++ Standard Library Encapsulates complex data structures and algorithms CSC 330 OO Software Design 1 We ve emphasized the importance of software reuse. Recognizing that many data structures and algorithms
More informationI source_beg, source_end; // defines a range of values in a source container // defines the beginning of a range in a destination container
Generic Algorithms We have encountered and put to use the concept of generic classes, particularly generic containers. Generic containers could be characterized as implementations of ADTs that are re usable
More informationEL2310 Scientific Programming
Lecture 16: STL, C++1y (ramviyas@kth.se) Overview Overview Lecture 16: STL and C++1y Reminders Wrap up C++11 Reminders The help sessions and deadline C++ help session: Fri 24.10.2015, 15:00-17:00, Room
More informationSTL. Zoltán Porkoláb: C++11/14 1
STL Generic programming An example inserters, iterator-adapters, functors Efficiency Memory consuption characteristics Std::array Forward_list Unordered containers in C++11 Zoltán Porkoláb: C++11/14 1
More informationTemplates Templates are functions or classes that are parameterized. We have already seen a few in STL:
Templates Templates are functions or classes that are parameterized. We have already seen a few in STL: std::vector< int > std::vector< double > std::list< std::vector< >> std::unordered_map< int, bool
More informationProgramming in C++ using STL. Rex Jaeschke
Programming in C++ using STL Rex Jaeschke Programming in C++ using STL 1997, 1999, 2002, 2007, 2009 Rex Jaeschke. All rights reserved. Edition: 2.0 All rights reserved. No part of this publication may
More informationStandard Template Library
Standard Template Library Wednesday, October 10, 2007 10:09 AM 9.3 "Quick Peek" STL history 1990s Alex Stepanov & Meng Lee of HP Labs 1994 ANSI/IS0 standard Components Container class templates Iterators
More informationIntroduction to C++ Day 2
1/39 Introduction to C++ Day 2 Marco Frailis INAF Osservatorio Astronomico di Trieste Contributions from: Stefano Sartor (INAF) 2/39 Memory layout of a C/C++ program // recursive greatest common divisor
More informationCSCI-1200 Data Structures Fall 2017 Lecture 10 Vector Iterators & Linked Lists
CSCI-1200 Data Structures Fall 2017 Lecture 10 Vector Iterators & Linked Lists Review from Lecture 9 Explored a program to maintain a class enrollment list and an associated waiting list. Unfortunately,
More informationEE 355 Unit 10. C++ STL - Vectors and Deques. Mark Redekopp
1 EE 355 Unit 10 C++ STL - Vectors and Deques Mark Redekopp 2 Templates We ve built a list to store integers But what if we want a list of double s or char s or other objects We would have to define the
More informationC++ Standard Template Library. Contents. Pierre Fierz. 1 Introduction. 2 Organization of STL Header Files. Organization of STL Header Files
Contents Chapter 3 1 Lecture Advanced C++ 05.03.2012 2 3 4 Associative 5 Associative 6 Bernese University of Applied Sciences School of Engineering and Information Technology Division of Computer Science
More informationTell compiler ValueType is a generic type. public: void push_back(const ValueType& elem); // rest of implementation }
template class StrVector { Tell compiler ValueType is a generic type. public: void push_back(const ValueType& elem); // rest of implementation } template class
More informationCSS 342 Data Structures, Algorithms, and Discrete Mathematics I. Standard Template Library
CSS 342 Data Structures, Algorithms, and Discrete Mathematics I Standard Template Library 1 Standard Template Library Need to understand basic data types, so we build them ourselves Once understood, we
More informationStandard Template Library. Outline
C++ Standard Template Library Spring 2015 Yanjun Li CS2200 1 Outline Standard Template Library Containers & Iterators STL vector STL list STL stack STL queue Fall 2008 Yanjun Li CS2200 2 Software Engineering
More informationProgramming Abstractions
Programming Abstractions C S 1 0 6 B Cynthia Lee Today s Topics ADTs Containers within containers Example: anagram finder Recursion First steps in this fun/crazy new concept Factorial! Compound Containers
More informationPolymorphism. Programming in C++ A problem of reuse. Swapping arguments. Session 4 - Genericity, Containers. Code that works for many types.
Session 4 - Genericity, Containers Polymorphism Code that works for many types. Dr Christos Kloukinas City, UoL http://staff.city.ac.uk/c.kloukinas/cpp (slides originally produced by Dr Ross Paterson)
More informationPrefix Trees Tables in Practice
Prefix Trees CS 311 Data Structures and Algorithms Lecture Slides Friday, December 7, 2007 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org 2005
More informationTeaching with the STL
Teaching with the STL Joseph Bergin Pace University Michael Berman Rowan College of New Jersey 1 Part 1 Introduction to STL Concepts 2 STL: What and Why Generic data structures (containers) and algorithms
More informationWorking with Batches of Data
Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/ hkaiser/fall_2012/csc1254.html 2 Abstract So far we looked at simple read a string print a string problems. Now we will look at more complex problems
More informationModule 9. Templates & STL
Module 9 Templates & STL Objectives In this module Learn about templates Construct function templates and class templates STL 2 Introduction Templates: enable you to write generic code for related functions
More informationDataStruct 9. Hash Tables, Maps, Skip Lists, and Dictionaries
2013-2 DataStruct 9. Hash Tables, Maps, Skip Lists, and Dictionaries Michael T. Goodrich, et. al, Data Structures and Algorithms in C++, 2 nd Ed., John Wiley & Sons, Inc., 2011. November 22, 2013 Advanced
More informationOverview. Part II: Containers and Algorithms. Overview. Overview
Part II: Containers and Algorithms Overview Sequential Containers Associative Containers Generic Algorithms C++ is about efficient programming with abstractions. The Standard Library is a good example:
More informationPatterns: Working with Arrays
Steven Zeil October 14, 2013 Outline 1 Static & Dynamic Allocation Static Allocation Dynamic Allocation 2 Partially Filled Arrays Adding Elements Searching for Elements Removing Elements 3 Arrays and Templates
More informationCSCI-1200 Data Structures Fall 2017 Lecture 9 Iterators & STL Lists
Review from Lecture 8 CSCI-1200 Data Structures Fall 2017 Lecture 9 Iterators & STL Lists Designing our own container classes Dynamically allocated memory in classes Copy constructors, assignment operators,
More informationDynamic Storage Exercise
Dynamic Storage Exercise Dynamic Storage Exercise int i; while (std::cin >> i)... reads inputs as long as there are more available. Write a code snippet which reads inputs as described above, and which
More informationOutline. Function calls and results Returning objects by value. return value optimization (RVO) Call by reference or by value?
Outline EDAF50 C++ Programming 6... 1 Function calls 2 Sven Gestegård Robertz Computer Science, LTH 2018 3 Standard library algorithms Insert iterators 4 Iterators Different kinds of iterators stream iterators
More informationTemplates and STL Vectors
Templates and STL Vectors Let s start with a singly-linked-list class of strings. The code to free the list from memory is missing. Here is the relevant code: class Node private: string name; Node* next;
More informationECE 2400 Computer Systems Programming Fall 2017 Topic 15: C++ Templates
ECE 2400 Computer Systems Programming Fall 2017 Topic 15: C++ Templates School of Electrical and Computer Engineering Cornell University revision: 2017-11-08-09-37 1 Function Templates 2 2 Class Templates
More information9. C++ advanced (II): Templates
Motivation Goal: generic vector class and functionality. Examples 9. C++ advanced (II): Templates vector vd(10); vector vi(10); vector vi(20); auto nd = vd vd; // norm (vector of double)
More informationSTL components. STL: C++ Standard Library Standard Template Library (STL) Main Ideas. Components. Encapsulates complex data structures and algorithms
STL: C++ Standard Library Standard Template Library (STL) Encapsulates complex data structures and algorithms is a library of generic container classes which are both efficient and functional C++ STL developed
More information9. C++ advanced (II): Templates
9. C++ advanced (II): Templates 263 Motivation 264 Goal: generic vector class and functionality. Examples vector vd(10); vector vi(10); vector vi(20); auto nd = vd vd; // norm (vector
More informationvector<int> second (4,100); // four ints with value 100 vector<int> third (second.begin(),second.end()); // iterating through second
C++ Vector Constructors explicit vector ( const Allocator& = Allocator() ); explicit vector ( size_type n, const T& value= T(), const Allocator& = Allocator() ); template vector (
More informationProgramming Abstractions
Programming Abstractions C S 1 0 6 B Cynthia Lee Compound Containers I t s t u r t l e s a l l t h e w a y down Comparing two similar codes: Vector numbers; numbers.add(1); numbers.add(2); numbers.add(3);
More informationThe Standard Template Library Classes
The Standard Template Library Classes Lecture 33 Sections 9.7, 9.8 Robb T. Koether Hampden-Sydney College Wed, Apr 23, 2014 Robb T. Koether (Hampden-Sydney College) The Standard Template Library Classes
More informationC++ II. Bálint Joó Jefferson Lab, Newport News, VA given at Jefferson Lab Graduate Lecture Series July 19, 2006
C++ II Bálint Joó (bjoo@jlab.org) Jefferson Lab, Newport News, VA given at Jefferson Lab Graduate Lecture Series July 19, 2006 1 Recap from Last Time We discussed C or Fortran 77 in C++ basic types, loops,
More informationScientific programming (in C++)
Scientific programming (in C++) F. Giacomini INFN-CNAF School on Open Science Cloud Perugia, June 2017 https://baltig.infn.it/giaco/201706_perugia_cpp What is C++ C++ is a programming language that is:
More informationCS 103 Unit 11. Linked Lists. Mark Redekopp
1 CS 103 Unit 11 Linked Lists Mark Redekopp 2 NULL Pointer Just like there was a null character in ASCII = '\0' whose ue was 0 There is a NULL pointer whose ue is 0 NULL is "keyword" you can use in C/C++
More informationG Programming Languages Spring 2010 Lecture 11. Robert Soulé, New York University
G22.2110-001 Programming Languages Spring 2010 Lecture 11 Robert Soulé, New York University 1 Review Last week Constructors, Destructors, and Assignment Operators Classes and Functions: Design and Declaration
More informationSuppose that you want to use two libraries with a bunch of useful classes and functions, but some names collide:
COMP151 Namespaces Motivation [comp151] 1 Suppose that you want to use two libraries with a bunch of useful classes and functions, but some names collide: // File: gnutils.h class Stack {... ; class Some
More informationSixth lecture; classes, objects, reference operator.
Sixth lecture; classes, objects, reference operator. 1 Some notes on the administration of the class: From here on out, homework assignments should be a bit shorter, and labs a bit longer. My office hours
More informationMajor Language Changes, pt. 1
C++0x What is C++0x? Updated version of C++ language. Addresses unresolved problems in C++03. Almost completely backwards compatible. Greatly increases expressiveness (and complexity!) of language. Greatly
More informationint main(){ int main(){ We want to understand this in depth! std::vector<int> v(10,0); // Vector of length 10
We look back #include #include . C++ advanced (I) Repetition: vectors, pointers and iterators, range for, keyword auto, a class for vectors, subscript-operator, move-construction, iterators
More informationCOMP6771 Advanced C++ Programming
1. COMP6771 Advanced C++ Programming Week 7 Part One: Member Templates and 2016 www.cse.unsw.edu.au/ cs6771 2. Member Templates Consider this STL code: 1 #include 2 #include 3 #include
More informationModule 4. l Graph Algorithms-MST. l HW3. l OO class point. C++ for C Programmers by Ira Pohl
Module 4 Graph Algorithms-MST HW3 OO class point Homework Week 3 Already built a graph (Abstract Data Type) Used Dijkstra algorithm to generate graph based on density and size Computed average length Minimum
More informationWentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. C++ Kitchen Sink. Lecture 14.
Lecture 14 1 Exceptions Iterators Random numbers Casting Enumerations Pairs The Big Three Outline 2 Error Handling It is often easier to write a program by first assuming that nothing incorrect will happen
More informationThe Inefficiency of C++ Fact or Fiction? Anders Lundgren IAR Systems
The Inefficiency of C++ Fact or Fiction? Anders Lundgren IAR Systems C++ C++ is a general-purpose programming language designed to make programming more enjoyable for the serious programmer. What you don
More informationModernizing C++ March 18. Kevin Funk
Modernizing C++ Kevin Funk March 18 Code modernization is an essential part of the software development discipline. If you neglect modernizing your code, your project could miss out on improvements that
More informationToday. andyoucanalsoconsultchapters6amd7inthetextbook. cis15-fall2007-parsons-lectvii.1 2
TEMPLATES Today This lecture looks at techniques for generic programming: Generic pointers Templates The standard template library Thebestreferenceis: http://www.cppreference.com/index.html andyoucanalsoconsultchapters6amd7inthetextbook.
More informationItem 3: Predicates, Part 2: Matters of State
ITEM1_11new.fm Page 1 Tuesday, November 27, 2001 12:41 PM Item 3: Predicates, Part 2: Matters of State ITEM 3: PREDICATES, PART 2: MATTERS OF STATE DIFFICULTY: 7 Following up from the introduction given
More informationThe Standard Template Library
The Standard Template Library The Standard Template Library A library of data structures. Built using templates. We will use it extend FMLib to multiple stocks. But rst we need to learn some techniques
More informationCOMP6771 Advanced C++ Programming
1.. COMP6771 Advanced C++ Programming Week 6 Part One: Function Templates 2016 www.cse.unsw.edu.au/ cs6771 2.. Constants Two notions of immutability: const: A promise not to change this value. Used primarily
More informationDue Date: See Blackboard
Source File: ~/2305/lab33.C Input: under control of main function Output: under control of main function Value: 3 The Shell sort, named after its inventor Donald Shell, provides a simple and efficient
More informationI m sure you have been annoyed at least once by having to type out types like this:
Type Inference The first thing I m going to talk about is type inference. C++11 provides mechanisms which make the compiler deduce the types of expressions. These features allow you to make your code more
More informationG52CPP C++ Programming Lecture 18
G52CPP C++ Programming Lecture 18 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Welcome Back 2 Last lecture Operator Overloading Strings and streams 3 Operator overloading - what to know
More informationThe Standard Template Library. An introduction
1 The Standard Template Library An introduction 2 Standard Template Library (STL) Objective: Reuse common code Common constructs: Generic containers and algorithms STL Part of the C++ Standard Library
More information12. Dictionaries. Dictionary. Idea. Other idea
Dictionary 12. Dictionaries Dictionary, Self-ordering List, Implementation of Dictionaries with Array / List /Sip lists. [Ottman/Widmayer, Kap. 3.3,1.7, Cormen et al, Kap. Problem 17-5] ADT to manage eys
More informationLecture 8. Xiaoguang Wang. February 13th, 2014 STAT 598W. (STAT 598W) Lecture 8 1 / 47
Lecture 8 Xiaoguang Wang STAT 598W February 13th, 2014 (STAT 598W) Lecture 8 1 / 47 Outline 1 Introduction: C++ 2 Containers 3 Classes (STAT 598W) Lecture 8 2 / 47 Outline 1 Introduction: C++ 2 Containers
More informationC++ Objects Overloading Other C++ Peter Kristensen
Peter Kristensen 2012-12-03 Peter Kristensen Outline 1 What s this thing anyway 2 3 Functions Operators 4 Templates STL A better C 11 Peter Kristensen Overview What s this thing anyway 1 What s this thing
More informationThe Standard C++ Library
The Standard C++ Library Main Ideas Purpose Flexibility Efficiency Simple & Uniform Interface Q: What types can we put in a template param? A: Type which models the requested concept. Concepts - Example
More informationCOMP6771 Advanced C++ Programming
1........ COMP6771 Advanced C++ Programming Week 4 Part Three: Function Objects and 2016 www.cse.unsw.edu.au/ cs6771 2........ Converting Class Types to bool Convenient to use a class object as bool to
More information