Stl design overview

132
The STL design: an overview HCM City C++ users meetup Germán Diago Gómez May 22nd, 2016 Germán Diago Gómez The STL design: an overview May 22nd, 2016 1 / 32

Transcript of Stl design overview

Page 1: Stl design overview

The STL design: an overviewHCM City C++ users meetup

Germán Diago Gómez

May 22nd, 2016

Germán Diago Gómez The STL design: an overview May 22nd, 2016 1 / 32

Page 2: Stl design overview

Overview Introduction

Goals of this talk

introduce STL fundamental ideas

understand the design choices that drove its current designlight introduction to each of its fundamental parts

Germán Diago Gómez The STL design: an overview May 22nd, 2016 2 / 32

Page 3: Stl design overview

Overview Introduction

Goals of this talk

introduce STL fundamental ideasunderstand the design choices that drove its current design

light introduction to each of its fundamental parts

Germán Diago Gómez The STL design: an overview May 22nd, 2016 2 / 32

Page 4: Stl design overview

Overview Introduction

Goals of this talk

introduce STL fundamental ideasunderstand the design choices that drove its current designlight introduction to each of its fundamental parts

Germán Diago Gómez The STL design: an overview May 22nd, 2016 2 / 32

Page 5: Stl design overview

Overview Introduction

Goals of this talk

introduce STL fundamental ideasunderstand the design choices that drove its current designlight introduction to each of its fundamental parts

Germán Diago Gómez The STL design: an overview May 22nd, 2016 2 / 32

Page 6: Stl design overview

Overview Introduction

Goals of this talk

introduce STL fundamental ideasunderstand the design choices that drove its current designlight introduction to each of its fundamental parts

Germán Diago Gómez The STL design: an overview May 22nd, 2016 2 / 32

Page 7: Stl design overview

Overview Introduction

Non-goals

not a detailed, fine-grained overview

not lots of examples

due to time constraints

Germán Diago Gómez The STL design: an overview May 22nd, 2016 3 / 32

Page 8: Stl design overview

Overview Introduction

Non-goals

not a detailed, fine-grained overviewnot lots of examples

due to time constraints

Germán Diago Gómez The STL design: an overview May 22nd, 2016 3 / 32

Page 9: Stl design overview

Overview Introduction

Non-goals

not a detailed, fine-grained overviewnot lots of examples

due to time constraints

Germán Diago Gómez The STL design: an overview May 22nd, 2016 3 / 32

Page 10: Stl design overview

Fundamentals

STL

STL stands for Standard Template Library

it is a subset of the C++ Standard Libraryits main author is Alexander Stepanovgot accepted into ISO C++98 standard library

Germán Diago Gómez The STL design: an overview May 22nd, 2016 4 / 32

Page 11: Stl design overview

Fundamentals

STL

STL stands for Standard Template Libraryit is a subset of the C++ Standard Library

its main author is Alexander Stepanovgot accepted into ISO C++98 standard library

Germán Diago Gómez The STL design: an overview May 22nd, 2016 4 / 32

Page 12: Stl design overview

Fundamentals

STL

STL stands for Standard Template Libraryit is a subset of the C++ Standard Libraryits main author is Alexander Stepanov

got accepted into ISO C++98 standard library

Germán Diago Gómez The STL design: an overview May 22nd, 2016 4 / 32

Page 13: Stl design overview

Fundamentals

STL

STL stands for Standard Template Libraryit is a subset of the C++ Standard Libraryits main author is Alexander Stepanovgot accepted into ISO C++98 standard library

Germán Diago Gómez The STL design: an overview May 22nd, 2016 4 / 32

Page 14: Stl design overview

Fundamentals

Design

general

allows a high degree of customization through compositionextensible: you can add new components to the frameworkreusable without loss of performace compared to hand-written codeintensive use of generic programming

Germán Diago Gómez The STL design: an overview May 22nd, 2016 5 / 32

Page 15: Stl design overview

Fundamentals

Design

generalallows a high degree of customization through composition

extensible: you can add new components to the frameworkreusable without loss of performace compared to hand-written codeintensive use of generic programming

Germán Diago Gómez The STL design: an overview May 22nd, 2016 5 / 32

Page 16: Stl design overview

Fundamentals

Design

generalallows a high degree of customization through compositionextensible: you can add new components to the framework

reusable without loss of performace compared to hand-written codeintensive use of generic programming

Germán Diago Gómez The STL design: an overview May 22nd, 2016 5 / 32

Page 17: Stl design overview

Fundamentals

Design

generalallows a high degree of customization through compositionextensible: you can add new components to the frameworkreusable without loss of performace compared to hand-written code

intensive use of generic programming

Germán Diago Gómez The STL design: an overview May 22nd, 2016 5 / 32

Page 18: Stl design overview

Fundamentals

Design

generalallows a high degree of customization through compositionextensible: you can add new components to the frameworkreusable without loss of performace compared to hand-written codeintensive use of generic programming

Germán Diago Gómez The STL design: an overview May 22nd, 2016 5 / 32

Page 19: Stl design overview

Fundamentals

STL main components

containers

iteratorsalgorithmsutilities (not the focus of this talk)

Germán Diago Gómez The STL design: an overview May 22nd, 2016 6 / 32

Page 20: Stl design overview

Fundamentals

STL main components

containersiterators

algorithmsutilities (not the focus of this talk)

Germán Diago Gómez The STL design: an overview May 22nd, 2016 6 / 32

Page 21: Stl design overview

Fundamentals

STL main components

containersiteratorsalgorithms

utilities (not the focus of this talk)

Germán Diago Gómez The STL design: an overview May 22nd, 2016 6 / 32

Page 22: Stl design overview

Fundamentals

STL main components

containersiteratorsalgorithmsutilities (not the focus of this talk)

Germán Diago Gómez The STL design: an overview May 22nd, 2016 6 / 32

Page 23: Stl design overview

Fundamentals

Why generic programming

allows compile-time polymorphism combined with overloading

allows customized code generation at compile-timeallows choose best optimization based on overloading, which is acompile-time mechanismallows high degree of customization, for both algorithms and data structureswithout loss of performance

Germán Diago Gómez The STL design: an overview May 22nd, 2016 7 / 32

Page 24: Stl design overview

Fundamentals

Why generic programming

allows compile-time polymorphism combined with overloadingallows customized code generation at compile-time

allows choose best optimization based on overloading, which is acompile-time mechanismallows high degree of customization, for both algorithms and data structureswithout loss of performance

Germán Diago Gómez The STL design: an overview May 22nd, 2016 7 / 32

Page 25: Stl design overview

Fundamentals

Why generic programming

allows compile-time polymorphism combined with overloadingallows customized code generation at compile-timeallows choose best optimization based on overloading, which is acompile-time mechanism

allows high degree of customization, for both algorithms and data structureswithout loss of performance

Germán Diago Gómez The STL design: an overview May 22nd, 2016 7 / 32

Page 26: Stl design overview

Fundamentals

Why generic programming

allows compile-time polymorphism combined with overloadingallows customized code generation at compile-timeallows choose best optimization based on overloading, which is acompile-time mechanismallows high degree of customization, for both algorithms and data structureswithout loss of performance

Germán Diago Gómez The STL design: an overview May 22nd, 2016 7 / 32

Page 27: Stl design overview

Fundamentals

Why generic programming (2)

types can retroactively model a concept

example: array pointers are iterators

OO alternative: uses run-time polymorphism and dispatch

performance penalty

Germán Diago Gómez The STL design: an overview May 22nd, 2016 8 / 32

Page 28: Stl design overview

Fundamentals

Why generic programming (2)

types can retroactively model a conceptexample: array pointers are iterators

OO alternative: uses run-time polymorphism and dispatch

performance penalty

Germán Diago Gómez The STL design: an overview May 22nd, 2016 8 / 32

Page 29: Stl design overview

Fundamentals

Why generic programming (2)

types can retroactively model a conceptexample: array pointers are iterators

OO alternative: uses run-time polymorphism and dispatch

performance penalty

Germán Diago Gómez The STL design: an overview May 22nd, 2016 8 / 32

Page 30: Stl design overview

Fundamentals

Why generic programming (2)

types can retroactively model a conceptexample: array pointers are iterators

OO alternative: uses run-time polymorphism and dispatchperformance penalty

Germán Diago Gómez The STL design: an overview May 22nd, 2016 8 / 32

Page 31: Stl design overview

Fundamentals

Concepts briefly explained

Concepts are the foundation of generic programming

a Concept is a set of requirements that a type must meet

the syntactic requirements that a type must meetthe semantic requirements that these syntactic requirements must meetoptionally, associated types for that conceptalgorithms: include the big O cost associated to them

In C++ these are the requirements that your template parameters need tofullfill. They are stated in the documentation, since there is no languagesupport (yet) for Concepts

Germán Diago Gómez The STL design: an overview May 22nd, 2016 9 / 32

Page 32: Stl design overview

Fundamentals

Concepts briefly explained

Concepts are the foundation of generic programminga Concept is a set of requirements that a type must meet

the syntactic requirements that a type must meetthe semantic requirements that these syntactic requirements must meetoptionally, associated types for that conceptalgorithms: include the big O cost associated to them

In C++ these are the requirements that your template parameters need tofullfill. They are stated in the documentation, since there is no languagesupport (yet) for Concepts

Germán Diago Gómez The STL design: an overview May 22nd, 2016 9 / 32

Page 33: Stl design overview

Fundamentals

Concepts briefly explained

Concepts are the foundation of generic programminga Concept is a set of requirements that a type must meet

the syntactic requirements that a type must meet

the semantic requirements that these syntactic requirements must meetoptionally, associated types for that conceptalgorithms: include the big O cost associated to them

In C++ these are the requirements that your template parameters need tofullfill. They are stated in the documentation, since there is no languagesupport (yet) for Concepts

Germán Diago Gómez The STL design: an overview May 22nd, 2016 9 / 32

Page 34: Stl design overview

Fundamentals

Concepts briefly explained

Concepts are the foundation of generic programminga Concept is a set of requirements that a type must meet

the syntactic requirements that a type must meetthe semantic requirements that these syntactic requirements must meet

optionally, associated types for that conceptalgorithms: include the big O cost associated to them

In C++ these are the requirements that your template parameters need tofullfill. They are stated in the documentation, since there is no languagesupport (yet) for Concepts

Germán Diago Gómez The STL design: an overview May 22nd, 2016 9 / 32

Page 35: Stl design overview

Fundamentals

Concepts briefly explained

Concepts are the foundation of generic programminga Concept is a set of requirements that a type must meet

the syntactic requirements that a type must meetthe semantic requirements that these syntactic requirements must meetoptionally, associated types for that concept

algorithms: include the big O cost associated to them

In C++ these are the requirements that your template parameters need tofullfill. They are stated in the documentation, since there is no languagesupport (yet) for Concepts

Germán Diago Gómez The STL design: an overview May 22nd, 2016 9 / 32

Page 36: Stl design overview

Fundamentals

Concepts briefly explained

Concepts are the foundation of generic programminga Concept is a set of requirements that a type must meet

the syntactic requirements that a type must meetthe semantic requirements that these syntactic requirements must meetoptionally, associated types for that conceptalgorithms: include the big O cost associated to them

In C++ these are the requirements that your template parameters need tofullfill. They are stated in the documentation, since there is no languagesupport (yet) for Concepts

Germán Diago Gómez The STL design: an overview May 22nd, 2016 9 / 32

Page 37: Stl design overview

Fundamentals

Concepts briefly explained

Concepts are the foundation of generic programminga Concept is a set of requirements that a type must meet

the syntactic requirements that a type must meetthe semantic requirements that these syntactic requirements must meetoptionally, associated types for that conceptalgorithms: include the big O cost associated to them

In C++ these are the requirements that your template parameters need tofullfill. They are stated in the documentation, since there is no languagesupport (yet) for Concepts

Germán Diago Gómez The STL design: an overview May 22nd, 2016 9 / 32

Page 38: Stl design overview

Fundamentals

Concepts briefly explained (2)

similar to the way a virtual function sets requirements on derived types

but at compile-time

when a type fullfills the requirements of a concept we say it models thatconcept

similar to when we say a derived class implements requirements from a baseclass

types do not need to inherit from any class to model a Concept → moreloosely coupled

Germán Diago Gómez The STL design: an overview May 22nd, 2016 10 / 32

Page 39: Stl design overview

Fundamentals

Concepts briefly explained (2)

similar to the way a virtual function sets requirements on derived typesbut at compile-time

when a type fullfills the requirements of a concept we say it models thatconcept

similar to when we say a derived class implements requirements from a baseclass

types do not need to inherit from any class to model a Concept → moreloosely coupled

Germán Diago Gómez The STL design: an overview May 22nd, 2016 10 / 32

Page 40: Stl design overview

Fundamentals

Concepts briefly explained (2)

similar to the way a virtual function sets requirements on derived typesbut at compile-time

when a type fullfills the requirements of a concept we say it models thatconcept

similar to when we say a derived class implements requirements from a baseclass

types do not need to inherit from any class to model a Concept → moreloosely coupled

Germán Diago Gómez The STL design: an overview May 22nd, 2016 10 / 32

Page 41: Stl design overview

Fundamentals

Concepts briefly explained (2)

similar to the way a virtual function sets requirements on derived typesbut at compile-time

when a type fullfills the requirements of a concept we say it models thatconcept

similar to when we say a derived class implements requirements from a baseclass

types do not need to inherit from any class to model a Concept → moreloosely coupled

Germán Diago Gómez The STL design: an overview May 22nd, 2016 10 / 32

Page 42: Stl design overview

Fundamentals

Concepts briefly explained (2)

similar to the way a virtual function sets requirements on derived typesbut at compile-time

when a type fullfills the requirements of a concept we say it models thatconcept

similar to when we say a derived class implements requirements from a baseclass

types do not need to inherit from any class to model a Concept → moreloosely coupled

Germán Diago Gómez The STL design: an overview May 22nd, 2016 10 / 32

Page 43: Stl design overview

Fundamentals

Concepts example: LessThanComparable

syntactic requirements

your type must work with operator< and return a type convertible to bool

semantic requirements for LessThanComparable operator<

∀a, !(a < a)a < b ⇐⇒ !(b < a)a < b ∧ b < c =⇒ a < c

associated types (optionally)

Germán Diago Gómez The STL design: an overview May 22nd, 2016 11 / 32

Page 44: Stl design overview

Fundamentals

Concepts example: LessThanComparable

syntactic requirementsyour type must work with operator< and return a type convertible to bool

semantic requirements for LessThanComparable operator<

∀a, !(a < a)a < b ⇐⇒ !(b < a)a < b ∧ b < c =⇒ a < c

associated types (optionally)

Germán Diago Gómez The STL design: an overview May 22nd, 2016 11 / 32

Page 45: Stl design overview

Fundamentals

Concepts example: LessThanComparable

syntactic requirementsyour type must work with operator< and return a type convertible to bool

semantic requirements for LessThanComparable operator<

∀a, !(a < a)a < b ⇐⇒ !(b < a)a < b ∧ b < c =⇒ a < c

associated types (optionally)

Germán Diago Gómez The STL design: an overview May 22nd, 2016 11 / 32

Page 46: Stl design overview

Fundamentals

Concepts example: LessThanComparable

syntactic requirementsyour type must work with operator< and return a type convertible to bool

semantic requirements for LessThanComparable operator<∀a, !(a < a)

a < b ⇐⇒ !(b < a)a < b ∧ b < c =⇒ a < c

associated types (optionally)

Germán Diago Gómez The STL design: an overview May 22nd, 2016 11 / 32

Page 47: Stl design overview

Fundamentals

Concepts example: LessThanComparable

syntactic requirementsyour type must work with operator< and return a type convertible to bool

semantic requirements for LessThanComparable operator<∀a, !(a < a)a < b ⇐⇒ !(b < a)

a < b ∧ b < c =⇒ a < c

associated types (optionally)

Germán Diago Gómez The STL design: an overview May 22nd, 2016 11 / 32

Page 48: Stl design overview

Fundamentals

Concepts example: LessThanComparable

syntactic requirementsyour type must work with operator< and return a type convertible to bool

semantic requirements for LessThanComparable operator<∀a, !(a < a)a < b ⇐⇒ !(b < a)a < b ∧ b < c =⇒ a < c

associated types (optionally)

Germán Diago Gómez The STL design: an overview May 22nd, 2016 11 / 32

Page 49: Stl design overview

Fundamentals

Concepts example: LessThanComparable

syntactic requirementsyour type must work with operator< and return a type convertible to bool

semantic requirements for LessThanComparable operator<∀a, !(a < a)a < b ⇐⇒ !(b < a)a < b ∧ b < c =⇒ a < c

associated types (optionally)

Germán Diago Gómez The STL design: an overview May 22nd, 2016 11 / 32

Page 50: Stl design overview

Fundamentals

More Concepts examples

BinaryPredicateDefaultConstructibleMany others

Germán Diago Gómez The STL design: an overview May 22nd, 2016 12 / 32

Page 51: Stl design overview

Containers

Introduction

Containers allow you to store collections of data in different data structures thatbest suite your needs.

Germán Diago Gómez The STL design: an overview May 22nd, 2016 13 / 32

Page 52: Stl design overview

Containers

STL containers classification

sequence containers

std::array<T>, std::vector<T>, std::list<T>. . .

associative containers

ordered → std::set. . .unordered → std::unordered_map. . .

container adaptors

std::priority_queue, std::stack. . .

Germán Diago Gómez The STL design: an overview May 22nd, 2016 14 / 32

Page 53: Stl design overview

Containers

STL containers classification

sequence containersstd::array<T>, std::vector<T>, std::list<T>. . .

associative containers

ordered → std::set. . .unordered → std::unordered_map. . .

container adaptors

std::priority_queue, std::stack. . .

Germán Diago Gómez The STL design: an overview May 22nd, 2016 14 / 32

Page 54: Stl design overview

Containers

STL containers classification

sequence containersstd::array<T>, std::vector<T>, std::list<T>. . .

associative containers

ordered → std::set. . .unordered → std::unordered_map. . .

container adaptors

std::priority_queue, std::stack. . .

Germán Diago Gómez The STL design: an overview May 22nd, 2016 14 / 32

Page 55: Stl design overview

Containers

STL containers classification

sequence containersstd::array<T>, std::vector<T>, std::list<T>. . .

associative containersordered → std::set. . .

unordered → std::unordered_map. . .

container adaptors

std::priority_queue, std::stack. . .

Germán Diago Gómez The STL design: an overview May 22nd, 2016 14 / 32

Page 56: Stl design overview

Containers

STL containers classification

sequence containersstd::array<T>, std::vector<T>, std::list<T>. . .

associative containersordered → std::set. . .unordered → std::unordered_map. . .

container adaptors

std::priority_queue, std::stack. . .

Germán Diago Gómez The STL design: an overview May 22nd, 2016 14 / 32

Page 57: Stl design overview

Containers

STL containers classification

sequence containersstd::array<T>, std::vector<T>, std::list<T>. . .

associative containersordered → std::set. . .unordered → std::unordered_map. . .

container adaptors

std::priority_queue, std::stack. . .

Germán Diago Gómez The STL design: an overview May 22nd, 2016 14 / 32

Page 58: Stl design overview

Containers

STL containers classification

sequence containersstd::array<T>, std::vector<T>, std::list<T>. . .

associative containersordered → std::set. . .unordered → std::unordered_map. . .

container adaptorsstd::priority_queue, std::stack. . .

Germán Diago Gómez The STL design: an overview May 22nd, 2016 14 / 32

Page 59: Stl design overview

Containers

STL containers traversal

depends on the kind iterators provided (more later)

random access, bidirectional, forward containers, etc.

Germán Diago Gómez The STL design: an overview May 22nd, 2016 15 / 32

Page 60: Stl design overview

Containers

STL containers traversal

depends on the kind iterators provided (more later)random access, bidirectional, forward containers, etc.

Germán Diago Gómez The STL design: an overview May 22nd, 2016 15 / 32

Page 61: Stl design overview

Iterators

Introduction

Iterators are used to traverse ranges

Iterators are an abstraction for positions

they are modeled after C pointers in C++’s concrete case

you can do a traversal with two iteratorsthey are not the same as an iterator in other languages

Java/C# iterator similar to a pair of iterators in C++

a pair of iterators is usually called a range in C++

Germán Diago Gómez The STL design: an overview May 22nd, 2016 16 / 32

Page 62: Stl design overview

Iterators

Introduction

Iterators are used to traverse rangesIterators are an abstraction for positions

they are modeled after C pointers in C++’s concrete case

you can do a traversal with two iteratorsthey are not the same as an iterator in other languages

Java/C# iterator similar to a pair of iterators in C++

a pair of iterators is usually called a range in C++

Germán Diago Gómez The STL design: an overview May 22nd, 2016 16 / 32

Page 63: Stl design overview

Iterators

Introduction

Iterators are used to traverse rangesIterators are an abstraction for positions

they are modeled after C pointers in C++’s concrete case

you can do a traversal with two iteratorsthey are not the same as an iterator in other languages

Java/C# iterator similar to a pair of iterators in C++

a pair of iterators is usually called a range in C++

Germán Diago Gómez The STL design: an overview May 22nd, 2016 16 / 32

Page 64: Stl design overview

Iterators

Introduction

Iterators are used to traverse rangesIterators are an abstraction for positions

they are modeled after C pointers in C++’s concrete case

you can do a traversal with two iterators

they are not the same as an iterator in other languages

Java/C# iterator similar to a pair of iterators in C++

a pair of iterators is usually called a range in C++

Germán Diago Gómez The STL design: an overview May 22nd, 2016 16 / 32

Page 65: Stl design overview

Iterators

Introduction

Iterators are used to traverse rangesIterators are an abstraction for positions

they are modeled after C pointers in C++’s concrete case

you can do a traversal with two iteratorsthey are not the same as an iterator in other languages

Java/C# iterator similar to a pair of iterators in C++

a pair of iterators is usually called a range in C++

Germán Diago Gómez The STL design: an overview May 22nd, 2016 16 / 32

Page 66: Stl design overview

Iterators

Introduction

Iterators are used to traverse rangesIterators are an abstraction for positions

they are modeled after C pointers in C++’s concrete case

you can do a traversal with two iteratorsthey are not the same as an iterator in other languages

Java/C# iterator similar to a pair of iterators in C++

a pair of iterators is usually called a range in C++

Germán Diago Gómez The STL design: an overview May 22nd, 2016 16 / 32

Page 67: Stl design overview

Iterators

Introduction

Iterators are used to traverse rangesIterators are an abstraction for positions

they are modeled after C pointers in C++’s concrete case

you can do a traversal with two iteratorsthey are not the same as an iterator in other languages

Java/C# iterator similar to a pair of iterators in C++

a pair of iterators is usually called a range in C++

Germán Diago Gómez The STL design: an overview May 22nd, 2016 16 / 32

Page 68: Stl design overview

Iterators

Iterator categories

several kinds of iterators

iterators form a hierarchy of Concepts

not implemented as inheritance in the librarythey are Concepts

RandomAccessIterator → BidirectionalIterator →ForwardIterator → InputIterator

OutputIterator is any iterator that can write to the element it points to

Germán Diago Gómez The STL design: an overview May 22nd, 2016 17 / 32

Page 69: Stl design overview

Iterators

Iterator categories

several kinds of iteratorsiterators form a hierarchy of Concepts

not implemented as inheritance in the librarythey are Concepts

RandomAccessIterator → BidirectionalIterator →ForwardIterator → InputIterator

OutputIterator is any iterator that can write to the element it points to

Germán Diago Gómez The STL design: an overview May 22nd, 2016 17 / 32

Page 70: Stl design overview

Iterators

Iterator categories

several kinds of iteratorsiterators form a hierarchy of Concepts

not implemented as inheritance in the library

they are Concepts

RandomAccessIterator → BidirectionalIterator →ForwardIterator → InputIterator

OutputIterator is any iterator that can write to the element it points to

Germán Diago Gómez The STL design: an overview May 22nd, 2016 17 / 32

Page 71: Stl design overview

Iterators

Iterator categories

several kinds of iteratorsiterators form a hierarchy of Concepts

not implemented as inheritance in the librarythey are Concepts

RandomAccessIterator → BidirectionalIterator →ForwardIterator → InputIterator

OutputIterator is any iterator that can write to the element it points to

Germán Diago Gómez The STL design: an overview May 22nd, 2016 17 / 32

Page 72: Stl design overview

Iterators

Iterator categories

several kinds of iteratorsiterators form a hierarchy of Concepts

not implemented as inheritance in the librarythey are Concepts

RandomAccessIterator → BidirectionalIterator →ForwardIterator → InputIterator

OutputIterator is any iterator that can write to the element it points to

Germán Diago Gómez The STL design: an overview May 22nd, 2016 17 / 32

Page 73: Stl design overview

Iterators

Iterator categories

several kinds of iteratorsiterators form a hierarchy of Concepts

not implemented as inheritance in the librarythey are Concepts

RandomAccessIterator → BidirectionalIterator →ForwardIterator → InputIterator

OutputIterator is any iterator that can write to the element it points to

Germán Diago Gómez The STL design: an overview May 22nd, 2016 17 / 32

Page 74: Stl design overview

Iterators

Iterator categories (2)

every iterator category supports a set of operations

InputIterator

element accessincrement iterator position by onesingle traversal

ForwardIterator

InputIterator + support for multiple traversals

BidirectionalIterator

ForwardIterator + supports decrementing position by one

RandomAccessIterator

BidirectionalIterator + supports jumping to arbitrary position in O(1)think of a pointer to C array position

Germán Diago Gómez The STL design: an overview May 22nd, 2016 18 / 32

Page 75: Stl design overview

Iterators

Iterator categories (2)

every iterator category supports a set of operationsInputIterator

element accessincrement iterator position by onesingle traversal

ForwardIterator

InputIterator + support for multiple traversals

BidirectionalIterator

ForwardIterator + supports decrementing position by one

RandomAccessIterator

BidirectionalIterator + supports jumping to arbitrary position in O(1)think of a pointer to C array position

Germán Diago Gómez The STL design: an overview May 22nd, 2016 18 / 32

Page 76: Stl design overview

Iterators

Iterator categories (2)

every iterator category supports a set of operationsInputIterator

element access

increment iterator position by onesingle traversal

ForwardIterator

InputIterator + support for multiple traversals

BidirectionalIterator

ForwardIterator + supports decrementing position by one

RandomAccessIterator

BidirectionalIterator + supports jumping to arbitrary position in O(1)think of a pointer to C array position

Germán Diago Gómez The STL design: an overview May 22nd, 2016 18 / 32

Page 77: Stl design overview

Iterators

Iterator categories (2)

every iterator category supports a set of operationsInputIterator

element accessincrement iterator position by one

single traversal

ForwardIterator

InputIterator + support for multiple traversals

BidirectionalIterator

ForwardIterator + supports decrementing position by one

RandomAccessIterator

BidirectionalIterator + supports jumping to arbitrary position in O(1)think of a pointer to C array position

Germán Diago Gómez The STL design: an overview May 22nd, 2016 18 / 32

Page 78: Stl design overview

Iterators

Iterator categories (2)

every iterator category supports a set of operationsInputIterator

element accessincrement iterator position by onesingle traversal

ForwardIterator

InputIterator + support for multiple traversals

BidirectionalIterator

ForwardIterator + supports decrementing position by one

RandomAccessIterator

BidirectionalIterator + supports jumping to arbitrary position in O(1)think of a pointer to C array position

Germán Diago Gómez The STL design: an overview May 22nd, 2016 18 / 32

Page 79: Stl design overview

Iterators

Iterator categories (2)

every iterator category supports a set of operationsInputIterator

element accessincrement iterator position by onesingle traversal

ForwardIterator

InputIterator + support for multiple traversals

BidirectionalIterator

ForwardIterator + supports decrementing position by one

RandomAccessIterator

BidirectionalIterator + supports jumping to arbitrary position in O(1)think of a pointer to C array position

Germán Diago Gómez The STL design: an overview May 22nd, 2016 18 / 32

Page 80: Stl design overview

Iterators

Iterator categories (2)

every iterator category supports a set of operationsInputIterator

element accessincrement iterator position by onesingle traversal

ForwardIteratorInputIterator + support for multiple traversals

BidirectionalIterator

ForwardIterator + supports decrementing position by one

RandomAccessIterator

BidirectionalIterator + supports jumping to arbitrary position in O(1)think of a pointer to C array position

Germán Diago Gómez The STL design: an overview May 22nd, 2016 18 / 32

Page 81: Stl design overview

Iterators

Iterator categories (2)

every iterator category supports a set of operationsInputIterator

element accessincrement iterator position by onesingle traversal

ForwardIteratorInputIterator + support for multiple traversals

BidirectionalIterator

ForwardIterator + supports decrementing position by one

RandomAccessIterator

BidirectionalIterator + supports jumping to arbitrary position in O(1)think of a pointer to C array position

Germán Diago Gómez The STL design: an overview May 22nd, 2016 18 / 32

Page 82: Stl design overview

Iterators

Iterator categories (2)

every iterator category supports a set of operationsInputIterator

element accessincrement iterator position by onesingle traversal

ForwardIteratorInputIterator + support for multiple traversals

BidirectionalIteratorForwardIterator + supports decrementing position by one

RandomAccessIterator

BidirectionalIterator + supports jumping to arbitrary position in O(1)think of a pointer to C array position

Germán Diago Gómez The STL design: an overview May 22nd, 2016 18 / 32

Page 83: Stl design overview

Iterators

Iterator categories (2)

every iterator category supports a set of operationsInputIterator

element accessincrement iterator position by onesingle traversal

ForwardIteratorInputIterator + support for multiple traversals

BidirectionalIteratorForwardIterator + supports decrementing position by one

RandomAccessIterator

BidirectionalIterator + supports jumping to arbitrary position in O(1)think of a pointer to C array position

Germán Diago Gómez The STL design: an overview May 22nd, 2016 18 / 32

Page 84: Stl design overview

Iterators

Iterator categories (2)

every iterator category supports a set of operationsInputIterator

element accessincrement iterator position by onesingle traversal

ForwardIteratorInputIterator + support for multiple traversals

BidirectionalIteratorForwardIterator + supports decrementing position by one

RandomAccessIteratorBidirectionalIterator + supports jumping to arbitrary position in O(1)

think of a pointer to C array position

Germán Diago Gómez The STL design: an overview May 22nd, 2016 18 / 32

Page 85: Stl design overview

Iterators

Iterator categories (2)

every iterator category supports a set of operationsInputIterator

element accessincrement iterator position by onesingle traversal

ForwardIteratorInputIterator + support for multiple traversals

BidirectionalIteratorForwardIterator + supports decrementing position by one

RandomAccessIteratorBidirectionalIterator + supports jumping to arbitrary position in O(1)think of a pointer to C array position

Germán Diago Gómez The STL design: an overview May 22nd, 2016 18 / 32

Page 86: Stl design overview

Iterators

Why are iterators important

abstract traversal from the underlying data structure

decouple algorithms implementation from data structure (later more)can implement algorithms based on its iterator category (later more)

containers just need to provide a begin/end sequence pair

let you reduce implementation effort on algorithms

Germán Diago Gómez The STL design: an overview May 22nd, 2016 19 / 32

Page 87: Stl design overview

Iterators

Why are iterators important

abstract traversal from the underlying data structuredecouple algorithms implementation from data structure (later more)

can implement algorithms based on its iterator category (later more)

containers just need to provide a begin/end sequence pair

let you reduce implementation effort on algorithms

Germán Diago Gómez The STL design: an overview May 22nd, 2016 19 / 32

Page 88: Stl design overview

Iterators

Why are iterators important

abstract traversal from the underlying data structuredecouple algorithms implementation from data structure (later more)can implement algorithms based on its iterator category (later more)

containers just need to provide a begin/end sequence pair

let you reduce implementation effort on algorithms

Germán Diago Gómez The STL design: an overview May 22nd, 2016 19 / 32

Page 89: Stl design overview

Iterators

Why are iterators important

abstract traversal from the underlying data structuredecouple algorithms implementation from data structure (later more)can implement algorithms based on its iterator category (later more)

containers just need to provide a begin/end sequence pair

let you reduce implementation effort on algorithms

Germán Diago Gómez The STL design: an overview May 22nd, 2016 19 / 32

Page 90: Stl design overview

Iterators

Why are iterators important

abstract traversal from the underlying data structuredecouple algorithms implementation from data structure (later more)can implement algorithms based on its iterator category (later more)

containers just need to provide a begin/end sequence pair

let you reduce implementation effort on algorithms

Germán Diago Gómez The STL design: an overview May 22nd, 2016 19 / 32

Page 91: Stl design overview

Algorithms

Introduction

algorithms let you perform operations on your data

STL algorithms design choices are a bit suprising at first

Germán Diago Gómez The STL design: an overview May 22nd, 2016 20 / 32

Page 92: Stl design overview

Algorithms

Introduction

algorithms let you perform operations on your dataSTL algorithms design choices are a bit suprising at first

Germán Diago Gómez The STL design: an overview May 22nd, 2016 20 / 32

Page 93: Stl design overview

Algorithms

Algorithm design choices

it was decided to implement algorithms as free functions, not as memberfunctions

it was decided that it would take Iterator s as input, instead of Containersconsequence: algorithms are decoupled from containers

Germán Diago Gómez The STL design: an overview May 22nd, 2016 21 / 32

Page 94: Stl design overview

Algorithms

Algorithm design choices

it was decided to implement algorithms as free functions, not as memberfunctionsit was decided that it would take Iterator s as input, instead of Containers

consequence: algorithms are decoupled from containers

Germán Diago Gómez The STL design: an overview May 22nd, 2016 21 / 32

Page 95: Stl design overview

Algorithms

Algorithm design choices

it was decided to implement algorithms as free functions, not as memberfunctionsit was decided that it would take Iterator s as input, instead of Containersconsequence: algorithms are decoupled from containers

Germán Diago Gómez The STL design: an overview May 22nd, 2016 21 / 32

Page 96: Stl design overview

Algorithms

STL algorithms/iterators conventions

algorithm specifications use half-open ranges for algorithms

(a, b]a is included in the range. b is not included in the range

containers provide begin, end and its variants

begin points to the first element of the containerend points one past the last element of the container traversal

thus, passing begin and end to an algorithm will traverse the whole sequencesome algorithms take three iterators: a range + the beginning of a secondrange where to put the output

C++14: these algorithms, called "three-legged" algorithms, were addedoverloads to pass two ranges. Example: std::equal

Germán Diago Gómez The STL design: an overview May 22nd, 2016 22 / 32

Page 97: Stl design overview

Algorithms

STL algorithms/iterators conventions

algorithm specifications use half-open ranges for algorithms(a, b]

a is included in the range. b is not included in the range

containers provide begin, end and its variants

begin points to the first element of the containerend points one past the last element of the container traversal

thus, passing begin and end to an algorithm will traverse the whole sequencesome algorithms take three iterators: a range + the beginning of a secondrange where to put the output

C++14: these algorithms, called "three-legged" algorithms, were addedoverloads to pass two ranges. Example: std::equal

Germán Diago Gómez The STL design: an overview May 22nd, 2016 22 / 32

Page 98: Stl design overview

Algorithms

STL algorithms/iterators conventions

algorithm specifications use half-open ranges for algorithms(a, b]a is included in the range. b is not included in the range

containers provide begin, end and its variants

begin points to the first element of the containerend points one past the last element of the container traversal

thus, passing begin and end to an algorithm will traverse the whole sequencesome algorithms take three iterators: a range + the beginning of a secondrange where to put the output

C++14: these algorithms, called "three-legged" algorithms, were addedoverloads to pass two ranges. Example: std::equal

Germán Diago Gómez The STL design: an overview May 22nd, 2016 22 / 32

Page 99: Stl design overview

Algorithms

STL algorithms/iterators conventions

algorithm specifications use half-open ranges for algorithms(a, b]a is included in the range. b is not included in the range

containers provide begin, end and its variants

begin points to the first element of the containerend points one past the last element of the container traversal

thus, passing begin and end to an algorithm will traverse the whole sequencesome algorithms take three iterators: a range + the beginning of a secondrange where to put the output

C++14: these algorithms, called "three-legged" algorithms, were addedoverloads to pass two ranges. Example: std::equal

Germán Diago Gómez The STL design: an overview May 22nd, 2016 22 / 32

Page 100: Stl design overview

Algorithms

STL algorithms/iterators conventions

algorithm specifications use half-open ranges for algorithms(a, b]a is included in the range. b is not included in the range

containers provide begin, end and its variantsbegin points to the first element of the container

end points one past the last element of the container traversal

thus, passing begin and end to an algorithm will traverse the whole sequencesome algorithms take three iterators: a range + the beginning of a secondrange where to put the output

C++14: these algorithms, called "three-legged" algorithms, were addedoverloads to pass two ranges. Example: std::equal

Germán Diago Gómez The STL design: an overview May 22nd, 2016 22 / 32

Page 101: Stl design overview

Algorithms

STL algorithms/iterators conventions

algorithm specifications use half-open ranges for algorithms(a, b]a is included in the range. b is not included in the range

containers provide begin, end and its variantsbegin points to the first element of the containerend points one past the last element of the container traversal

thus, passing begin and end to an algorithm will traverse the whole sequencesome algorithms take three iterators: a range + the beginning of a secondrange where to put the output

C++14: these algorithms, called "three-legged" algorithms, were addedoverloads to pass two ranges. Example: std::equal

Germán Diago Gómez The STL design: an overview May 22nd, 2016 22 / 32

Page 102: Stl design overview

Algorithms

STL algorithms/iterators conventions

algorithm specifications use half-open ranges for algorithms(a, b]a is included in the range. b is not included in the range

containers provide begin, end and its variantsbegin points to the first element of the containerend points one past the last element of the container traversal

thus, passing begin and end to an algorithm will traverse the whole sequence

some algorithms take three iterators: a range + the beginning of a secondrange where to put the output

C++14: these algorithms, called "three-legged" algorithms, were addedoverloads to pass two ranges. Example: std::equal

Germán Diago Gómez The STL design: an overview May 22nd, 2016 22 / 32

Page 103: Stl design overview

Algorithms

STL algorithms/iterators conventions

algorithm specifications use half-open ranges for algorithms(a, b]a is included in the range. b is not included in the range

containers provide begin, end and its variantsbegin points to the first element of the containerend points one past the last element of the container traversal

thus, passing begin and end to an algorithm will traverse the whole sequencesome algorithms take three iterators: a range + the beginning of a secondrange where to put the output

C++14: these algorithms, called "three-legged" algorithms, were addedoverloads to pass two ranges. Example: std::equal

Germán Diago Gómez The STL design: an overview May 22nd, 2016 22 / 32

Page 104: Stl design overview

Algorithms

STL algorithms/iterators conventions

algorithm specifications use half-open ranges for algorithms(a, b]a is included in the range. b is not included in the range

containers provide begin, end and its variantsbegin points to the first element of the containerend points one past the last element of the container traversal

thus, passing begin and end to an algorithm will traverse the whole sequencesome algorithms take three iterators: a range + the beginning of a secondrange where to put the output

C++14: these algorithms, called "three-legged" algorithms, were addedoverloads to pass two ranges. Example: std::equal

Germán Diago Gómez The STL design: an overview May 22nd, 2016 22 / 32

Page 105: Stl design overview

Algorithms

STL algorithms/iterators conventions (2)

no memory management in algorithms. Beware

you must have space in the target output range

example: std::copy must have enough space for the output

std::remove algorithms do not resize your containers

they just put the rubbish to remove at the end of your container. You must callContainer::erase.

you can use iterator adaptors that make room for elements if you do notknow how much space you will need. example: back_insert_iterator.

Germán Diago Gómez The STL design: an overview May 22nd, 2016 23 / 32

Page 106: Stl design overview

Algorithms

STL algorithms/iterators conventions (2)

no memory management in algorithms. Bewareyou must have space in the target output range

example: std::copy must have enough space for the outputstd::remove algorithms do not resize your containers

they just put the rubbish to remove at the end of your container. You must callContainer::erase.

you can use iterator adaptors that make room for elements if you do notknow how much space you will need. example: back_insert_iterator.

Germán Diago Gómez The STL design: an overview May 22nd, 2016 23 / 32

Page 107: Stl design overview

Algorithms

STL algorithms/iterators conventions (2)

no memory management in algorithms. Bewareyou must have space in the target output range

example: std::copy must have enough space for the output

std::remove algorithms do not resize your containers

they just put the rubbish to remove at the end of your container. You must callContainer::erase.

you can use iterator adaptors that make room for elements if you do notknow how much space you will need. example: back_insert_iterator.

Germán Diago Gómez The STL design: an overview May 22nd, 2016 23 / 32

Page 108: Stl design overview

Algorithms

STL algorithms/iterators conventions (2)

no memory management in algorithms. Bewareyou must have space in the target output range

example: std::copy must have enough space for the outputstd::remove algorithms do not resize your containers

they just put the rubbish to remove at the end of your container. You must callContainer::erase.

you can use iterator adaptors that make room for elements if you do notknow how much space you will need. example: back_insert_iterator.

Germán Diago Gómez The STL design: an overview May 22nd, 2016 23 / 32

Page 109: Stl design overview

Algorithms

STL algorithms/iterators conventions (2)

no memory management in algorithms. Bewareyou must have space in the target output range

example: std::copy must have enough space for the outputstd::remove algorithms do not resize your containers

they just put the rubbish to remove at the end of your container. You must callContainer::erase.

you can use iterator adaptors that make room for elements if you do notknow how much space you will need. example: back_insert_iterator.

Germán Diago Gómez The STL design: an overview May 22nd, 2016 23 / 32

Page 110: Stl design overview

Algorithms

STL algorithms/iterators conventions (2)

no memory management in algorithms. Bewareyou must have space in the target output range

example: std::copy must have enough space for the outputstd::remove algorithms do not resize your containers

they just put the rubbish to remove at the end of your container. You must callContainer::erase.

you can use iterator adaptors that make room for elements if you do notknow how much space you will need. example: back_insert_iterator.

Germán Diago Gómez The STL design: an overview May 22nd, 2016 23 / 32

Page 111: Stl design overview

Algorithms

Extensibility and adaptation

you can provide an algorithm based on iterator category: it will work on allexisting containers that model at least that iterator category

if you provide your iterators for you container, it just worksbasic arrays also work with algorithms

Germán Diago Gómez The STL design: an overview May 22nd, 2016 24 / 32

Page 112: Stl design overview

Algorithms

Extensibility and adaptation

you can provide an algorithm based on iterator category: it will work on allexisting containers that model at least that iterator categoryif you provide your iterators for you container, it just works

basic arrays also work with algorithms

Germán Diago Gómez The STL design: an overview May 22nd, 2016 24 / 32

Page 113: Stl design overview

Algorithms

Extensibility and adaptation

you can provide an algorithm based on iterator category: it will work on allexisting containers that model at least that iterator categoryif you provide your iterators for you container, it just worksbasic arrays also work with algorithms

Germán Diago Gómez The STL design: an overview May 22nd, 2016 24 / 32

Page 114: Stl design overview

Algorithms

Implementation effort reduction

container-based implementation: N algorithms for M data structures

O(N ·M) implementations

iterator-based implementation: N algorithms independent of the datastructure

Germán Diago Gómez The STL design: an overview May 22nd, 2016 25 / 32

Page 115: Stl design overview

Algorithms

Implementation effort reduction

container-based implementation: N algorithms for M data structuresO(N ·M) implementations

iterator-based implementation: N algorithms independent of the datastructure

Germán Diago Gómez The STL design: an overview May 22nd, 2016 25 / 32

Page 116: Stl design overview

Algorithms

Implementation effort reduction

container-based implementation: N algorithms for M data structuresO(N ·M) implementations

iterator-based implementation: N algorithms independent of the datastructure

Germán Diago Gómez The STL design: an overview May 22nd, 2016 25 / 32

Page 117: Stl design overview

Algorithms

Implementation effort reduction (2)

STL ≈ 60 algorithms and 13 data structures (without counting adapters andnative arrays)

container-based algorithms: 60 ∗ 13 = 780 implementationsiterator-based algorithms: 60 implementations, plus maybe some optimizationoverloads in cases where algorithms can be optimized for a specific iteratorcategory

remember that algorithms must be as good as hand-written algorithms for anyuse case

Germán Diago Gómez The STL design: an overview May 22nd, 2016 26 / 32

Page 118: Stl design overview

Algorithms

Implementation effort reduction (2)

STL ≈ 60 algorithms and 13 data structures (without counting adapters andnative arrays)

container-based algorithms: 60 ∗ 13 = 780 implementations

iterator-based algorithms: 60 implementations, plus maybe some optimizationoverloads in cases where algorithms can be optimized for a specific iteratorcategory

remember that algorithms must be as good as hand-written algorithms for anyuse case

Germán Diago Gómez The STL design: an overview May 22nd, 2016 26 / 32

Page 119: Stl design overview

Algorithms

Implementation effort reduction (2)

STL ≈ 60 algorithms and 13 data structures (without counting adapters andnative arrays)

container-based algorithms: 60 ∗ 13 = 780 implementationsiterator-based algorithms: 60 implementations, plus maybe some optimizationoverloads in cases where algorithms can be optimized for a specific iteratorcategory

remember that algorithms must be as good as hand-written algorithms for anyuse case

Germán Diago Gómez The STL design: an overview May 22nd, 2016 26 / 32

Page 120: Stl design overview

Algorithms

Implementation effort reduction (2)

STL ≈ 60 algorithms and 13 data structures (without counting adapters andnative arrays)

container-based algorithms: 60 ∗ 13 = 780 implementationsiterator-based algorithms: 60 implementations, plus maybe some optimizationoverloads in cases where algorithms can be optimized for a specific iteratorcategory

remember that algorithms must be as good as hand-written algorithms for anyuse case

Germán Diago Gómez The STL design: an overview May 22nd, 2016 26 / 32

Page 121: Stl design overview

Algorithms

STL algorithm example

Germán Diago Gómez The STL design: an overview May 22nd, 2016 27 / 32

Page 122: Stl design overview

Utilities

Utilities

Utilities include other useful components such as std::pair, std::function,type_traits, functional objects, std::tuple, std::unique_ptr,std::shared_ptr, etc.

Germán Diago Gómez The STL design: an overview May 22nd, 2016 28 / 32

Page 123: Stl design overview

Putting it all together

Typical algorithm usage

1 Choose an algorithm.

2 Provide the iterators from your container(s). for the algorithm throughbegin() and end() functions

3 Customize the behaviour of your algorithm through predicates/functionobjects.

Germán Diago Gómez The STL design: an overview May 22nd, 2016 29 / 32

Page 124: Stl design overview

Putting it all together

Typical algorithm usage

1 Choose an algorithm.2 Provide the iterators from your container(s). for the algorithm through

begin() and end() functions

3 Customize the behaviour of your algorithm through predicates/functionobjects.

Germán Diago Gómez The STL design: an overview May 22nd, 2016 29 / 32

Page 125: Stl design overview

Putting it all together

Typical algorithm usage

1 Choose an algorithm.2 Provide the iterators from your container(s). for the algorithm through

begin() and end() functions3 Customize the behaviour of your algorithm through predicates/function

objects.

Germán Diago Gómez The STL design: an overview May 22nd, 2016 29 / 32

Page 126: Stl design overview

Putting it all together

Example exercise

Read all the data for the spanish fooball league. We store the data in a leagueclass which is a collection of football_match_result records. The file is sortedby round. Every 10 matches it is a new round. Blank lines are accepted.

File spanish_football_league2015-2016.txtReal Madrid,2-1,MalagaRayo,0-2,Sevilla...

We will:

1 Get all matches for a given team2 Calculate the classification table3 Calculate the matches a given team won as a visitor

Germán Diago Gómez The STL design: an overview May 22nd, 2016 30 / 32

Page 127: Stl design overview

Putting it all together

Example exercise

Read all the data for the spanish fooball league. We store the data in a leagueclass which is a collection of football_match_result records. The file is sortedby round. Every 10 matches it is a new round. Blank lines are accepted.

File spanish_football_league2015-2016.txtReal Madrid,2-1,MalagaRayo,0-2,Sevilla...

We will:

1 Get all matches for a given team2 Calculate the classification table3 Calculate the matches a given team won as a visitor

Germán Diago Gómez The STL design: an overview May 22nd, 2016 30 / 32

Page 128: Stl design overview

Putting it all together

Example exercise

Read all the data for the spanish fooball league. We store the data in a leagueclass which is a collection of football_match_result records. The file is sortedby round. Every 10 matches it is a new round. Blank lines are accepted.

File spanish_football_league2015-2016.txtReal Madrid,2-1,MalagaRayo,0-2,Sevilla...

We will:1 Get all matches for a given team

2 Calculate the classification table3 Calculate the matches a given team won as a visitor

Germán Diago Gómez The STL design: an overview May 22nd, 2016 30 / 32

Page 129: Stl design overview

Putting it all together

Example exercise

Read all the data for the spanish fooball league. We store the data in a leagueclass which is a collection of football_match_result records. The file is sortedby round. Every 10 matches it is a new round. Blank lines are accepted.

File spanish_football_league2015-2016.txtReal Madrid,2-1,MalagaRayo,0-2,Sevilla...

We will:1 Get all matches for a given team2 Calculate the classification table

3 Calculate the matches a given team won as a visitor

Germán Diago Gómez The STL design: an overview May 22nd, 2016 30 / 32

Page 130: Stl design overview

Putting it all together

Example exercise

Read all the data for the spanish fooball league. We store the data in a leagueclass which is a collection of football_match_result records. The file is sortedby round. Every 10 matches it is a new round. Blank lines are accepted.

File spanish_football_league2015-2016.txtReal Madrid,2-1,MalagaRayo,0-2,Sevilla...

We will:1 Get all matches for a given team2 Calculate the classification table3 Calculate the matches a given team won as a visitor

Germán Diago Gómez The STL design: an overview May 22nd, 2016 30 / 32

Page 131: Stl design overview

Future STL-related work

Current status of future standardization

added parallel algorithms to C++17essentially, you do std::sort(parallel::par, begin(v), end(v)) andenjoy performance gains automatically

ranges-based STL, by Eric Niebler → Ranges v3 experimental implementation

you can do std::sort(v) and much morelazy evaluation and composition

v | view::transform([](auto const & elem) {...}) |view::remove_if([]...)

library includes, besides ranges, view s and action s, but these are notproposed for standardization yet

there is a TS for Concepts support in the language: Concepts TS latest draftimplementation available in GCC 6 with -fconcepts flag

Germán Diago Gómez The STL design: an overview May 22nd, 2016 31 / 32

Page 132: Stl design overview

Future STL-related work

Thank you

Germán Diago Gómez The STL design: an overview May 22nd, 2016 32 / 32