Standard Template Library
Transcription
Standard Template Library
'
$
Notes de cours
'
$
Standard Template Library
Ecole Nationale d’Ingénieurs de Brest
Table des matières
L’approche STL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Les itérateurs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Les classes de fonctions . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Programmation par objets
Le langage C++
— Standard Template Library —
Les conteneurs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Les adaptateurs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Les algorithmes génériques . . . . . . . . . . . . . . . . . . . . . . 145
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
J. Tisseau
– 1996/1997 –
&
'
Références . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
c jt . . . . . . . . 1/344
enib Standard Template Library
%
&
$
'
L’approche STL
c jt . . . . . . . . 2/344
enib %
$
L’approche STL
Bibliothèque de composants C++ génériques
L’approche STL
Fonctions : algorithmes génériques
sort, binary search, reverse, for each, accumulate, . . .
1. Une bibliothèque de composants C++ génériques
2. Du particulier au générique
Conteneurs : collections homogènes d’objets
vector, list, set, map, multimap, . . .
3. Des indices aux itérateurs, via les pointeurs
4. De la généricité des données à la généricité des structures
Itérateurs : sorte de pointeurs pour inspecter un conteneur
input iterator, random access iterator, ostream iterator, . . .
Objets fonction : encapsulation de fonctions dans des objets
plus, times, less equal, logical or, . . .
Adaptateurs : modificateurs d’interfaces de composants
stack, queue, priority queue, . . .
&
c jt . . . . . . . . 3/344
enib %
&
c jt . . . . . . . . 4/344
enib %
'
$
L’approche STL
'
Du particulier . . .
. . . au générique
int
max(int x, int y) { return x < y ? y : x ; }
template <class T>
const T&
max(const T& x, const T& y) { return x < y ? y : x ; }
int
max(int x, int y, int (*compare)(int,int)) {
return compare(x,y) ? y : x ;
}
template <class T, class Compare>
const T&
max(const T& x, const T& y, Compare compare) {
return compare(x, y) ? y : x ;
}
&
'
c jt . . . . . . . . 5/344
enib L’approche STL
%
&
$
'
c jt . . . . . . . . 6/344
enib %
$
L’approche STL
. . . via les pointeurs . . .
Des indices . . .
int
max element(const int* array, int n) {
int result = array[0] ;
for(int i = 1 ; i < n ; i++)
if(result < array[i]) result = array[i] ;
return result ;
}
&
$
L’approche STL
c jt . . . . . . . . 7/344
enib int*
max element(int* first, int* last) {
if(first == last) return first ;
int* result = first ;
while(++first != last)
if(*result < *first) result = first ;
return result ;
}
%
&
c jt . . . . . . . . 8/344
enib %
'
$
L’approche STL
'
. . . aux itérateurs génériques
max element (2)
template <class InputIterator>
InputIterator
max element(InputIterator first, InputIterator last) {
if(first == last) return first ;
InputIterator result = first ;
while(++first != last)
if(*result < *first) result = first ;
return result ;
}
&
'
c jt . . . . . . . . 9/344
enib L’approche STL
$
L’approche STL
STL
algo.h
template <class InputIterator, class Compare>
InputIterator
max element(InputIterator first, InputIterator last,
Compare compare) {
if (first == last) return first ;
InputIterator result = first ;
while(++first != last)
if(compare(*result,*first)) result = first ;
return result ;
}
%
&
$
'
Exemple d’utilisation : max element (2)
c jt . . . . . . . 10/344
enib %
$
L’approche STL
De la généricité des données . . .
// Sequences
template <class T> class vector ;
template <class T> class deque ;
template <class T> class list ;
bool str compare(const char* a, const char* b) {
return : :strcmp(a, b) < 0 ? 1 : 0 ;
}
char* names[] = { "Dany", "Alexis", "Serge", "Vincent" } ;
// Associative containers
template <class T1, class T2> class
template <class Key, class Compare>
template <class Key, class Compare>
template <class Key, class T, class
template <class Key, class T, class
cout << *max element(names, names + 4, str compare) << endl ;
&
c jt . . . . . . . 11/344
enib %
&
pair ;
class set ;
class multiset ;
Compare> class map ;
Compare> class multimap ;
c jt . . . . . . . 12/344
enib %
'
$
L’approche STL
'
. . . à la généricité des structures
Exemple d’utilisation : stack
stack< deque<int> > s1 ;
stack< vector<int> > s2 ;
// Containers adaptors
template <class Container> class stack ;
template <class Container> class queue ;
template <class Container> class priority queue ;
s1.push(42) ; s1.push(101) ; s1.push(69) ;
copy(s1.begin(), s1.end(), s2.begin()) ;
// Instantiations
stack< vector<double> > s ;
queue< deque<const char*> > q ;
priority queue< list<int> > p ;
&
'
while( !s2.empty()) {
cout << s2.top() << endl ;
s2.pop() ;
}
c jt . . . . . . . 13/344
enib Standard Template Library
%
&
$
'
c jt . . . . . . . 14/344
enib %
$
Itérateurs
Des pointeurs spécialisés
Les itérateurs
(p2 < p)
•
Les itérateurs
p
•
-= m
?
?
?
p[n]
3. input iterator<T,Distance> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
t1 = *p ; *p = t2 ;
4. forward iterator<T,Distance> . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
5. bidirectional iterator<T,Distance> . . . . . . . . . . . . . . . . . . . . . 29
p
•Z
6. random access iterator<T,Distance> . . . . . . . . . . . . . . . . . . . . . 34
?
7. Itérateurs dérivés . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
*p
?
Pointer
Z
Z
Z
Z
~
Z
++
8. Exemples d’utilisation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
c jt . . . . . . . 15/344
enib •
++
*p
2. output iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
(p1 > p)
+= n
Z
Z
Z
Z
Z
?
~
Z
=
--
1. Des pointeurs spécialisés . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
&
$
L’approche STL
InputIterator
t1 = *p ;
%
&
c jt . . . . . . . 16/344
enib %
'
$
Itérateurs
'
$
Itérateurs
output iterator
Itérateurs de base
p
•Z
Z
Z
Z
Z
~
Z
++
struct output iterator {} ;
?
*p
template <class T, class Distance>
struct input iterator {} ;
*p = t2 ;
template <class T, class Distance>
struct forward iterator {} ;
class OutputIterator : public output iterator {
public :
T& operator*(void) ;
OutputIterator& operator++(void) ;
OutputIterator operator++(int) ;
};
template <class T, class Distance>
struct bidirectional iterator {} ;
&
'
&
OutputIterator
template <class T, class Distance>
struct random access iterator {} ;
c jt . . . . . . . 17/344
enib Itérateurs
%
&
$
'
c jt . . . . . . . 18/344
enib $
Itérateurs
Exemple de définition : output iterator (1)
Exemple de définition : output iterator (2)
template <class T>
class OstreamIterator : public output iterator {
protected :
ostream* stream ;
char* string ;
public :
OstreamIterator(ostream& s) : stream(&s), string(0) {}
OstreamIterator(ostream& s, char* c)
: stream(&s), string(c) {}
à suivre ...
OstreamIterator<T>& operator=(const T& value) {
* stream << value ;
if( string) * stream << string ;
return *this ;
}
OstreamIterator<T>& operator*(void) { return *this ; }
OstreamIterator<T>& operator++(void) { return *this ; }
OstreamIterator<T>& operator++(int) { return *this ; }
} ; // end class OstreamIterator<T>
... fin
c jt . . . . . . . 19/344
enib %
&
%
c jt . . . . . . . 20/344
enib %
'
$
Itérateurs
'
$
Itérateurs
Exemple de définition : input iterator<T,Distance> (1)
input iterator<T,Distance>
p
•Z
Z
Z
Z
Z
~
Z
++
template <class T>
class IstreamIterator : public input iterator<T,ptrdiff t> {
protected :
istream* stream ;
T value ;
bool endMarker ;
void read() {
endMarker = (* stream) ? true : false ;
if( endMarker) * stream >> value ;
endMarker = (* stream) ? true : false ;
}
à suivre ...
?
*p
InputIterator
t1 = *p ;
template <class T, class Distance>
class InputIterator : public input iterator<T,Distance> {
public :
const T& operator*(void) const ;
InputIterator<T,Distance>& operator++(void) ;
InputIterator<T,Distance> operator++(int) ;
};
&
'
&
c jt . . . . . . . 21/344
enib Itérateurs
%
&
$
'
c jt . . . . . . . 22/344
enib $
Itérateurs
Exemple de définition : input iterator<T,Distance> (2)
Exemple de définition : input iterator<T,Distance> (3)
public :
IstreamIterator(void)
: stream(&cin), endMarker(false) {}
IstreamIterator(istream& s) : stream(&s) { read() ; }
const T& operator*(void) const { return value ; }
IstreamIterator<T>& operator++(void) {
read() ; return *this ;
}
IstreamIterator<T> operator++(int) {
IstreamIterator<T> tmp = *this ; read() ; return tmp ;
}
à suivre ...
friend bool operator==(const IstreamIterator<T>& x,
const IstreamIterator<T>& y) {
return x. stream == y. stream &&
x. endMarker == y. endMarker
||
x. endMarker == false &&
y. endMarker == false ;
}
} ; // end class IstreamIterator<T>
... fin
c jt . . . . . . . 23/344
enib %
&
%
c jt . . . . . . . 24/344
enib %
'
$
Itérateurs
'
$
Itérateurs
Exemple de définition : forward iterator (1)
forward iterator<T,Distance>
p
•Z
Z
Z
Z
Z
~
Z
++
template <class T>
struct list node { void* next ; T data ; } ;
?
*p
ForwardIterator
template <class T>
class list iterator : public forward iterator<T,ptrdiff t> {
protected :
list node<T>* node ;
list iterator(list node<T>* x) : node(x) {}
t1 = *p ; *p = t2 ;
template <class T, class Distance>
class ForwardIterator : public forward iterator<T,Distance> {
public :
T& operator*(void) ;
const T& operator*(void) const ;
ForwardIterator& operator++(void) ;
ForwardIterator operator++(int) ;
};
&
'
c jt . . . . . . . 25/344
enib Itérateurs
à suivre ...
%
&
$
'
c jt . . . . . . . 26/344
enib $
Itérateurs
Exemple de définition : forward iterator (2)
%
Exemple de définition : forward iterator (3)
public :
list iterator(void) {}
list iterator& operator++(void) {
node = (list node*)((* node).next) ; return *this ;
}
bool operator==(const list iterator& x) const {
return node == x. node ;
}
list iterator operator++(int) {
list iterator tmp = *this ; ++*this ; return tmp ;
}
T& operator*(void) const { return (* node).data ; }
};
... fin
à suivre ...
&
c jt . . . . . . . 27/344
enib %
&
c jt . . . . . . . 28/344
enib %
'
$
Itérateurs
'
$
Itérateurs
Exemple de définition : bidirectional iterator (1)
bidirectional iterator<T,Distance>
p
•
Z
Z
Z
Z
Z
?
=
~
Z
--
++
*p
template <class T>
struct list node { void* next ; void* previous ; T data ; } ;
BidirectionalIterator
template <class T>
class list iterator
: public bidirectional iterator<T, ptrdiff t> {
protected :
list node<T>* node ;
list iterator(list node<T>* x) : node(x) {}
t1 = *p ; *p = t2 ;
&
'
template <class T, class Distance>
class BidirectionalIterator : public bidirectional iterator<T,Distance> {
public :
T& operator*(void) ;
const T& operator*(void) const ;
ForwardIterator& operator++(void) ;
ForwardIterator operator++(int) ;
ForwardIterator& operator--(void) ;
ForwardIterator operator--(int) ;
};
c jt . . . . . . . 29/344
enib Itérateurs
à suivre ...
%
&
$
'
Exemple de définition : bidirectional iterator (2)
c jt . . . . . . . 30/344
enib %
$
Itérateurs
Exemple de définition : bidirectional iterator (3)
public :
list iterator(void) {}
list iterator<T>& operator++(void) {
node = (list node<T>*)((* node).next) ; return *this ;
}
bool operator==(const list iterator<T>& x) const {
return node == x. node ;
}
list iterator<T> operator++(int) {
list iterator<T> tmp = *this ; ++*this ; return tmp ;
}
à suivre ...
T& operator*(void) const { return (* node).data ; }
à suivre ...
&
c jt . . . . . . . 31/344
enib %
&
c jt . . . . . . . 32/344
enib %
'
$
Itérateurs
'
Exemple de définition : bidirectional iterator (4)
random access iterator<T,Distance>
(p2 < p)
•
?
'
Itérateurs
?
?
p[n]
RandomAccessIterator
RandomAccessIterator ≡ Pointer
%
&
$
'
c jt . . . . . . . 34/344
enib %
$
Itérateurs
Itérateurs dérivés
template <class T, class Distance>
class RandomAccessIterator : public random access iterator<T,Distance> {
public :
T& operator*(void) ;
const T& operator*(void) const ;
RandomAccessIterator& operator++(void) ;
RandomAccessIterator operator++(int) ;
RandomAccessIterator& operator--(void) ;
RandomAccessIterator operator--(int) ;
RandomAccessIterator& operator+=(Distance n) ;
RandomAccessIterator operator+(Distance n) ;
RandomAccessIterator& operator-=(Distance n) ;
RandomAccessIterator operator-(Distance n) ;
T& operator[](Distance n) ;
const T& operator[](Distance n) const ;
bool operator<(const RandomAccessIterator& iterator) const ;
};
c jt . . . . . . . 35/344
enib •
++
t1 = *p ; *p = t2 ;
random access iterator<T,Distance>
&
?
(p1 > p)
+= n
Z
Z
Z
Z
Z
?
~
Z
=
*p
list iterator<T> operator--(int) {
list iterator<T> tmp = *this ; --*this ; return tmp ;
}
} ; // end class list iterator<T>
... fin
c jt . . . . . . . 33/344
enib p
•
-= m
--
list iterator<T>& operator--(void) {
node = (list node<T>*)((* node).previous) ;
return *this ;
}
&
$
Itérateurs
%
&
template
: public
template
: public
template
: public
<class
output
<class
output
<class
output
Container> class back insert iterator
iterator ;
Container> class front insert iterator
iterator ;
Container> class insert iterator
iterator ;
template
: public
template
: public
<class T, class Distance> class istream iterator
input iterator<T, Distance> ;
<class T> class ostream iterator
output iterator ;
c jt . . . . . . . 36/344
enib %
'
$
Itérateurs
'
$
Itérateurs
Exemple d’utilisation : vector<T> : :iterator (1)
Itérateurs dérivés
template <class BidirectionalIterator, class T,
class Reference, class Distance>
class reverse bidirectional iterator
: public bidirectional iterator<T, Distance> ;
template <class RandomAccessIterator, class T,
class Reference, class Distance>
class reverse iterator
: public random access iterator<T, Distance> ;
vector<int> v ;
v.push back(1) ; v.push back(2) ; v.push back(3) ;
vector<int> : :iterator i = v.end() ;
cout << "last element is " << *--i << endl ;
i -= 2 ;
cout << "first element is " << *i << endl ;
template <class OutputIterator, class T>
class raw storage iterator : public output iterator ;
&
'
c jt . . . . . . . 37/344
enib Itérateurs
%
&
$
'
Exemple d’utilisation : vector<T> : :iterator (2)
c jt . . . . . . . 38/344
enib %
$
Itérateurs
Exemple d’utilisation : ostream iterator
vector<const char*> v ;
v.push back("hello ") ;
v.push back("world !") ;
int array[] = { 1, 5, 2, 4 } ;
char* string = "hello" ;
vector<const char*> : :iterator i ;
for(i = v.begin() ; i != v.end() ; i++) cout << *i << endl ;
ostream iterator<char> it1(cout) ;
copy(string, string + 5, it1) ;
cout << endl ;
ostream iterator<int> it2(cout) ;
copy(array, array + 4, it2) ;
cout << endl ;
&
c jt . . . . . . . 39/344
enib %
&
c jt . . . . . . . 40/344
enib %
'
$
Itérateurs
'
$
Standard Template Library
Exemple d’utilisation : istream iterator
Les classes de fonctions
Les classes de fonctions
int i = 0 ;
char buffer[100] ;
1. Surdéfinition de operator() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
2. Fonctions unaires et binaires . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
cin.unsetf(ios : :skipws) ;
// Disable white-space skipping.
cout << "Please enter a string : " ;
3. Fonctions arithmétiques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4. Fonctions logiques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
5. Pointeurs de fonctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
istream iterator<char, ptrdiff t> s(cin) ;
while(*s != ’\n’) buffer[i++] = *s++ ;
buffer[i] = ’\0’ ;
// Null terminate buffer.
cout << "read : " << buffer << endl ;
&
'
c jt . . . . . . . 41/344
enib Fonctions
6. Composition de fonctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
%
&
$
'
Surdéfinition de operator()
Fonctions unaires :
binary function<Arg1, Arg2, Result>
c jt . . . . . . . 43/344
enib STL
function.h
template <class Arg, class Result>
struct unary function {
typedef Arg argument type ;
typedef Result result type ;
};
unary function<Arg, Result>
template <class Arg1, class Arg2, class Result>
struct binary function {
typedef Arg1 first argument type ;
typedef Arg2 second argument type ;
typedef Result result type ;
};
Result operator()(Arg1 arg1, Arg2 arg2) const ;
&
%
$
Fonctions
unary/binary function
Result operator()(Arg arg) const ;
Fonctions binaires :
c jt . . . . . . . 42/344
enib %
&
c jt . . . . . . . 44/344
enib %
'
$
Fonctions
plus , minus
STL
function.h
times , divides
STL
function.h
template <class T>
struct times : binary function<T, T, T> {
T operator()(const T& x, const T& y) const {
return x * y ;
}
};
template <class T>
struct minus : binary function<T, T, T> {
T operator()(const T& x, const T& y) const {
return x - y ;
}
};
template <class T>
struct divides : binary function<T, T, T> {
T operator()(const T& x, const T& y) const {
return x / y ;
}
};
c jt . . . . . . . 45/344
enib Fonctions
modulus , negate
STL
%
&
$
'
c jt . . . . . . . 46/344
enib %
$
Fonctions
Exemple d’utilisation des fonctions arithmétiques
function.h
template <class T>
struct modulus : binary function<T, T, T> {
T operator()(const T& x, const T& y) const {
return x % y ;
}
};
int input1[4]
int input2[4]
int* first1 =
int* first2 =
= { 1, 6, 11, 8 } ;
= { 1, 5, 2, 3 } ;
&input1[0] ; int* last1 = &input1[4] ;
&input2[0] ;
int result = 0 ;
plus<int> add ; times<int> mult ;
template <class T>
struct negate : unary function<T, T> {
T operator()(const T& x) const {
return -x ;
}
};
&
$
Fonctions
template <class T>
struct plus : binary function<T, T, T> {
T operator()(const T& x, const T& y) const {
return x + y ;
}
};
&
'
'
while(first1 != last1)
result = add(result, mult(*first1++,*first2++)) ;
cout << "inner product = " << result << endl ;
c jt . . . . . . . 47/344
enib %
&
c jt . . . . . . . 48/344
enib %
'
$
Fonctions
equal to , not equal to
STL
STL
function.h
template <class T>
struct greater : binary function<T, T, bool> {
bool operator()(const T& x, const T& y) const {
return x > y ;
}
};
template <class T>
struct not equal to : binary function<T, T, bool> {
bool operator()(const T& x, const T& y) const {
return x != y ;
}
};
template <class T>
struct greater equal : binary function<T, T, bool> {
bool operator()(const T& x, const T& y) const {
return x >= y ;
}
};
c jt . . . . . . . 49/344
enib Fonctions
less , less equal
&
greater , greater equal
function.h
$
Fonctions
template <class T>
struct equal to : binary function<T, T, bool> {
bool operator()(const T& x, const T& y) const {
return x == y ;
}
};
&
'
'
STL
%
&
$
'
c jt . . . . . . . 50/344
enib $
Fonctions
ident , select1st
function.h
STL
projectn.h
template <class T>
struct less : binary function<T, T, bool> {
bool operator()(const T& x, const T& y) const {
return x < y ;
}
};
template <class T, class U>
struct ident : public unary function<T, U> {
const U& operator()(const T& x) const {
return x ;
}
};
template <class T>
struct less equal : binary function<T, T, bool> {
bool operator()(const T& x, const T& y) const {
return x <= y ;
}
};
template <class T, class U>
struct select1st : public unary function<T, U> {
const U& operator()(const T& x) const {
return x.first ;
}
};
c jt . . . . . . . 51/344
enib %
&
%
c jt . . . . . . . 52/344
enib %
'
$
Fonctions
logical and , logical or
STL
'
logical not
function.h
template <class T>
struct logical and : binary function<T, T, bool> {
bool operator()(const T& x, const T& y) const {
return x && y ;
}
};
$
Fonctions
STL
function.h
template <class T>
struct logical not : unary function<T, bool> {
bool operator()(const T& x) const {
return !x ;
}
};
template <class T>
struct logical or : binary function<T, T, bool> {
bool operator()(const T& x, const T& y) const {
return x || y ;
}
};
&
'
c jt . . . . . . . 53/344
enib Fonctions
%
&
$
'
Exemple d’utilisation des fonctions logiques
STL
function.h
template <class Arg, class Result>
class pointer to unary function
: public unary function<Arg, Result> {
protected :
Result (*ptr)(Arg) ;
public :
pointer to unary function(Result *x(Arg)) : ptr(x) {}
Result operator()(Arg x) const { return ptr(x) ; }
};
count if(input1, input1 + 7, logical not<bool>(), n) ;
cout << n << endl ;
transform(input1, input1 + 7, input2, output,
logical and<bool>()) ;
for(int i = 0 ; i < 4 ; i++) cout << output[i] << endl ;
c jt . . . . . . . 55/344
enib %
$
Fonctions
pointer to unary function
bool input1[7] = { 1, 0, 0, 1, 1, 1, 1 } ;
bool input2[7] = { 1, 1, 0, 0, 0, 1, 0 } ;
bool output[7] ;
int n = 0 ;
&
c jt . . . . . . . 54/344
enib %
&
c jt . . . . . . . 56/344
enib %
'
$
Fonctions
'
Exemple d’utilisation : pointer to unary function
pointer to binary function
int* p = find if(array, array + 3,
pointer to unary function<int, bool>(even)) ;
if(p != array + 3) cout << *p << " is even" << endl ;
'
c jt . . . . . . . 57/344
enib Fonctions
%
&
$
'
Exemple d’utilisation : pointer to binary function
int input1[4] = { 7, 2, 3, 5 } ;
int input2[4] = { 1, 5, 5, 8 } ;
int output[4] ;
transform(input1, input1 + 4, input2, output,
pointer to binary function<int, int, int>(sum)) ;
for(int i = 0 ; i < 4 ; i++) cout << output[i] << endl ;
c jt . . . . . . . 59/344
enib function.h
c jt . . . . . . . 58/344
enib %
&
%
$
Fonctions
unary compose
int sum(int x, int y) { return x + y ; }
&
STL
template <class Arg1, class Arg2, class Result>
class pointer to binary function
: public binary function<Arg1, Arg2, Result> {
protected :
Result (*ptr)(Arg1, Arg2) ;
public :
pointer to binary function(Result *x(Arg1, Arg2))
: ptr(x) {}
Result operator()(Arg1 x, Arg2 y) const {
return ptr(x, y) ;
}
};
bool even(int n) { return (n % 2) == 0 ; }
int array[3] = { 1, 2, 3 } ;
&
$
Fonctions
STL
function.h
template <class Operation1, class Operation2>
class unary compose
: public unary function<Operation2 : :argument type,
Operation1 : :result type> {
protected :
Operation1 op1 ; Operation2 op2 ;
public :
unary compose(const Operation1& x, const Operation2& y)
: op1(x), op2(y) {}
result type operator()(const argument type& x) const {
return op1(op2(x)) ;
}
};
c jt . . . . . . . 60/344
enib %
'
$
Fonctions
'
Utilitaire pour unary compose : compose1
$
Fonctions
Exemple d’utilisation : unary compose
template <class Oper1, class Oper2>
unary compose<Oper1, Oper2>
compose1(const Oper1& op1,
const Oper2& op2) {
return unary compose<Oper1, Oper2>(op1, op2) ;
}
struct square root : public unary function<double, double> {
double operator()(double x) const { return sqrt (x) ; }
};
int input[3] = { -1, -4, -16 } ;
int output[3] ;
transform(input, input + 3, output,
compose1(square root(), negate<int>())) ;
for(int i = 0 ; i < 3 ; i++) cout << output[i] << endl ;
&
'
c jt . . . . . . . 61/344
enib Fonctions
binary compose
&
STL
%
&
$
'
c jt . . . . . . . 63/344
enib %
$
Fonctions
Utilitaire pour binary compose : compose2
function.h
template <class Operation1, class Operation2,
class Operation3>
class binary compose
: public unary function<Operation2 : :argument type,
Operation1 : :result type> {
protected :
Operation1 op1 ; Operation2 op2 ; Operation3 op3 ;
public :
binary compose(const Operation1& x, const Operation2& y,
const Operation3& z) : op1(x), op2(y), op3(z) { }
result type operator()(const argument type& x) const
{ return op1(op2(x), op3(x)) ; }
};
c jt . . . . . . . 62/344
enib template <class Oper1, class Oper2, class Oper3>
binary compose<Oper1, Oper2, Oper3>
compose2(const Oper1& op1,
const Oper2& op2,
const Oper3& op3) {
return binary compose<Oper1, Oper2, Oper3>(op1, op2, op3) ;
}
%
&
c jt . . . . . . . 64/344
enib %
'
$
Fonctions
'
$
Standard Template Library
Exemple d’utilisation : binary compose
Les conteneurs
Les conteneurs
struct odd : public unary function<int, bool> {
bool operator()(int n) const { return (n % 2) == 1 ; }
};
struct positive : public unary function<int, bool> {
bool operator() (int n) const { return n >= 0 ; }
};
1. Séquences
(a) vector<T> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
(b) deque<T> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
(c) list<T> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
2. Arbres de recherche
(a) rb tree<Key,Value,KeyOfValue,Compare> . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
3. Tables associatives
int array[] = { -2, -1 , 0, 1, 2, 3 } ;
int* p = find if(array, array + 6,
compose2(logical and<bool>(), odd(), positive())) ;
if(p != array + 6) cout << *p << " odd and positive" << endl ;
(a) pair<T1,T2> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
(b) set<Key,Compare> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
(c) multiset<Key,Compare> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
(d) map<Key,T,Compare> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
(e) multimap<Key,T,Compare> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
&
c jt . . . . . . . 65/344
enib '
Séquences
STL
vector
%
&
$
'
Définitions
typedef
typedef
typedef
typedef
typedef
typedef
typedef
typedef
v.end()
•
?
v[0] v[1]
v.front()
&
?
v[4]
%
$
vector<T>
vector.h
template <class T> class vector ;
v.begin()
•
c jt . . . . . . . 66/344
enib vector<T> v ;
T value type ;
Allocator<T> :
Allocator<T> :
Allocator<T> :
Allocator<T> :
Allocator<T> :
Allocator<T> :
Allocator<T> :
:pointer pointer ;
:pointer iterator ;
:const pointer const iterator ;
:reference reference ;
:const reference const reference ;
:size type size type ;
:difference type difference type ;
v.back()
c jt . . . . . . . 67/344
enib %
&
c jt . . . . . . . 68/344
enib %
'
$
vector<T>
'
Inspecteurs
Allocations
size
size
size
bool
vector(void) ;
vector(size type n, const T& value = T()) ;
vector(const vector<T>& x) ;
vector(const iterator first, const iterator last) ;
vector<T>& operator=(const vector<T>& x) ;
void reserve(size type n) ;
'
c jt . . . . . . . 69/344
enib vector<T>
%
&
$
'
c jt . . . . . . . 70/344
enib %
$
vector<T>
Insertions et suppressions
Itérateurs
iterator begin(void) ;
const iterator begin(void) const ;
iterator end(void) ;
const iterator end(void) const ;
reverse iterator rbegin(void) ;
const reverse iterator rbegin(void) const ;
reverse iterator rend(void) ;
const reverse iterator rend(void) const ;
&
type size(void) const ;
type max size(void) const ;
type capacity(void) const ;
empty(void) const ;
reference operator[](size type n) ;
const reference operator[](size type n) const ;
reference front(void) ;
const reference front(void) const ;
reference back(void) ;
const reference back(void) const ;
~vector(void) ;
&
$
vector<T>
iterator insert(iterator position, const T& x) ;
void insert(iterator position, const iterator first,
const iterator last) ;
void insert(iterator position, size type n, const T& x) ;
void push back(const T& x) ;
void erase(iterator position) ;
void erase(iterator first, iterator last) ;
void pop back(void) ;
c jt . . . . . . . 71/344
enib %
&
c jt . . . . . . . 72/344
enib %
'
$
vector<T>
'
Exemple d’utilisation de la classe vector
$
Séquences
STL
deque
int array1[] = { 1, 4, 25 } ;
int array2[] = { 9, 16 } ;
vector<int> v(array1, array1 + 3) ;
deque.h
template <class T> class deque ;
v.begin()
•
v.insert(v.begin(), 0) ;
v.insert(v.end(), 36) ;
for(int i = 0 ; i < v.size() ; i++)
cout << "v[" << i << "] = " << v[i] << endl ;
v.end()
•
?
v[0] v[1]
v.front()
?
v[4]
deque<T> v ;
v.back()
v.insert(v.begin() + 3, array2, array2 + 2) ;
for(i = 0 ; i < v.size() ; i++)
cout << "v[" << i << "] = " << v[i] << endl ;
&
'
c jt . . . . . . . 73/344
enib deque<T>
%
&
$
'
c jt . . . . . . . 74/344
enib typedef
typedef
typedef
typedef
typedef
typedef
typedef
typedef
$
deque<T>
Définitions
%
Allocations
T value type ;
Allocator<T> data allocator type ;
Allocator<T> : :pointer pointer ;
Allocator<T> : :reference reference ;
Allocator<T> : :const reference const reference ;
Allocator<T> : :size type size type ;
Allocator<T> : :difference type difference type ;
Allocator<pointer> map allocator type ;
deque(void) ;
deque(size type n, const T& value = T()) ;
deque(const T* first, const T* last) ;
deque(const deque<T>& x) ;
deque<T>& operator=(const deque<T>& x) ;
~deque(void) ;
class iterator ; // random access iterator<T, difference type>
class const iterator ;
&
c jt . . . . . . . 75/344
enib %
&
c jt . . . . . . . 76/344
enib %
'
$
deque<T>
'
Inspecteurs
Itérateurs
bool empty(void) const ;
size type size(void) const ;
size type max size(void) const ;
iterator begin(void) ;
const iterator begin(void) const ;
iterator end(void) ;
const iterator end(void) const ;
reverse iterator rbegin(void) ;
const reverse iterator rbegin(void) const ;
reverse iterator rend(void) ;
const reverse iterator rend(void) const ;
reference operator[](size type n) ;
const reference operator[](size type n) const ;
reference front(void) ;
const reference front(void) const ;
reference back(void) ;
const reference back(void) const ;
&
c jt . . . . . . . 77/344
enib '
deque<T>
%
&
$
'
Insertions et suppressions
&
c jt . . . . . . . 78/344
enib %
$
deque<T>
Exemple d’utilisation de la classe deque
deque<int> d ;
iterator insert(iterator position, const T& x) ;
void insert(iterator position, size type n, const T& x) ;
void insert(iterator position, const T* first,
const T* last) ;
void push front(const T& x) ;
void push back(const T& x) ;
void
void
void
void
$
deque<T>
d.push back(4) ; d.push back(9) ; d.push back(16) ;
d.push front(1) ;
for(int i = 0 ; i < d.size() ; i++)
cout << "d[" << i << "] = " << d[i] << endl ;
d.pop front() ;
d[2] = 25 ;
for(i = 0 ; i < d.size() ; i++)
cout << "d[" << i << "] = " << d[i] << endl ;
erase(iterator position) ;
erase(iterator first, iterator last) ;
pop front(void) ;
pop back(void) ;
c jt . . . . . . . 79/344
enib %
&
c jt . . . . . . . 80/344
enib %
'
$
Séquences
STL
list
'
Définitions
list.h
typedef T value type ;
typedef Allocator<T> value allocator type ;
typedef Allocator<T> : :pointer pointer ;
typedef Allocator<T> : :reference reference ;
typedef Allocator<T> : :const reference const reference ;
typedef Allocator<list node> list node allocator type ;
typedef Allocator<list node> : :pointer link type ;
typedef Allocator<list node> : :size type size type ;
typedef Allocator<list node> : :difference type
difference type ;
template <class T> class list ;
v.begin()
•
•
•
v.front()
v.end()
•
*(++v.begin())
?
•
•
?
•
list<T> v ;
v.back()
&
'
•
c jt . . . . . . . 81/344
enib list<T>
%
&
$
'
class iterator ; //bidirectional iterator<T, difference type>
class const iterator ;
c jt . . . . . . . 82/344
enib %
$
list<T>
Inspecteurs
Allocations
bool empty(void) const ;
size type size(void) const ;
size type max size(void) const ;
list(void) ;
list(size type n, const T& value = T()) ;
list(const T* first, const T* last) ;
list(const list<T>& x) ;
list<T>& operator=(const list<T>& x) ;
reference front(void) ;
const reference front(void) const ;
reference back(void) ;
const reference back(void) const ;
~list(void) ;
&
$
list<T>
c jt . . . . . . . 83/344
enib %
&
c jt . . . . . . . 84/344
enib %
'
$
list<T>
'
Itérateurs
Insertions
iterator begin(void) ;
const iterator begin(void) const ;
iterator end(void) ;
const iterator end(void) ;
reverse iterator rbegin(void) ;
const reverse iterator rbegin(void) const ;
reverse iterator rend(void) ;
const reverse iterator rend(void) const ;
&
iterator insert(iterator position, const T& x) ;
void insert(iterator position, const T* first,
const T* last) ;
void insert(iterator position, const iterator first,
const iterator last) ;
void insert(iterator position, size type n, const T& x) ;
void push front(const T& x) ;
void push back(const T& x) ;
c jt . . . . . . . 85/344
enib '
list<T>
%
&
$
'
c jt . . . . . . . 86/344
enib &
%
$
list<T>
Suppressions
void
void
void
void
void
void
$
list<T>
Manipulations
erase(iterator position) ;
erase(iterator first, iterator last) ;
pop front(void) ;
pop back(void) ;
remove(const T& value) ;
unique(void) ;
void
void
void
void
swap(list<T>& x) ;
splice(iterator position, list<T>& x) ;
splice(iterator position, list<T>& x, iterator i) ;
splice(iterator position, list<T>& x, iterator first,
iterator last) ;
void merge(list<T>& x) ;
void reverse(void) ;
void sort(void) ;
c jt . . . . . . . 87/344
enib %
&
c jt . . . . . . . 88/344
enib %
'
$
list<T>
'
Exemple d’utilisation de la classe list
char array[] = { ’x’, ’l’, ’x’, ’t’,
list<char> str(array, array + 6) ;
list<char> : :iterator i ;
for(i = str.begin() ; i != str.end() ;
str.reverse() ;
for(i = str.begin() ; i != str.end() ;
str.remove(’x’) ;
for(i = str.begin() ; i != str.end() ;
str.unique() ;
for(i = str.begin() ; i != str.end() ;
str.sort() ;
for(i = str.begin() ; i != str.end() ;
&
'
STL
rb tree
’s’, ’s’ } ;
tree.h
template <class Key,class Value,class KeyOfValue,class Compare>
class rb tree ;
i++) cout << *i ;
i++) cout << *i ;
i++) cout << *i ;
i++) cout << *i ;
typedef Key key type ;
typedef Value value type ;
i++) cout << *i ;
c jt . . . . . . . 89/344
enib rb tree
%
&
$
'
c jt . . . . . . . 90/344
enib %
$
rb tree
Définitions
typedef
typedef
typedef
typedef
typedef
typedef
typedef
$
Arbres
Allocations
Allocator<Value> : :pointer pointer ;
Allocator<Value> : :reference reference ;
Allocator<Value> : :const reference const reference ;
Allocator<rb tree node> rb tree node allocator type ;
Allocator<rb tree node> : :pointer link type ;
Allocator<rb tree node> : :size type size type ;
Allocator<rb tree node> : :difference type
difference type ;
rb tree(const Compare& comp = Compare(), bool always = true) ;
rb tree(const value type* first, const value type* last,
const Compare& comp = Compare(), bool always = true) ;
rb tree(const rb tree<Key, Value, KeyOfValue, Compare>& x,
bool always = true) ;
rb tree<Key, Value, KeyOfValue, Compare>&
operator=(const rb tree<Key,Value,KeyOfValue,Compare>& x) ;
~rb tree(void) ;
&
c jt . . . . . . . 91/344
enib %
&
c jt . . . . . . . 92/344
enib %
'
$
rb tree
'
Inspecteurs
Inspecteurs
Compare key comp(void) const ;
bool empty(void) const ;
size type size(void) const ;
size type max size(void) const ;
size type count(const key type& x) const ;
&
'
iterator find(const key type& x) ;
const iterator find(const key type& x) const ;
iterator lower bound(const key type& x) ;
const iterator lower bound(const key type& x) const ;
iterator upper bound(const key type& x) ;
const iterator upper bound(const key type& x) const ;
pair<iterator, iterator> equal range(const key type& x) ;
pair<const iterator, const iterator>
equal range(const key type& x) const ;
c jt . . . . . . . 93/344
enib rb tree
%
&
$
'
c jt . . . . . . . 94/344
enib %
$
rb tree
Insertions et suppressions
Itérateurs
iterator begin(void) ;
const iterator begin(void) const ;
iterator end(void) ;
const iterator end(void) const ;
reverse iterator rbegin(void) ;
const reverse iterator rbegin(void) const ;
reverse iterator rend(void) ;
const reverse iterator rend(void) const ;
&
$
rb tree
pair<iterator, bool> insert(const value type& x) ;
iterator insert(iterator position, const value type& x) ;
void insert(iterator first, iterator last) ;
void insert(const value type* first, const value type* last) ;
void
size
void
void
c jt . . . . . . . 95/344
enib %
&
erase(iterator position) ;
type erase(const key type& x) ;
erase(iterator first, iterator last) ;
erase(const key type* first, const key type* last) ;
c jt . . . . . . . 96/344
enib %
'
$
Tables associatives
'
Les paires
T1 a
T2 b
STL
pair
pair.h
template <class T1, class T2>
struct pair {
T1 first ;
T2 second ;
pair(const T1& a, const T2& b) ;
};
Une paire est la réunion de deux objets de types quelconques au
sein d’une même structure.
first
$
Tables associatives
second
pair<T1,T2> p(a,b) ;
&
'
c jt . . . . . . . 97/344
enib pair<T1,T2>
%
&
$
'
c jt . . . . . . . 98/344
enib $
Tables associatives
Exemple d’utilisation de la classe pair
%
Les ensembles ordonnés
Un ensemble ordonné est une collection d’objets du même type
classés selon une relation d’ordre linéaire (<).
pair<int, double> p(1, 10.5) ;
cout << "p.first = " << p.first << endl ;
cout << "p.second = " << p.second << endl ;
1. Unicité des éléments
∀a, b ∈ E, a 6= b
2. Eléments comparables
∀a, b ∈ E, (a < b) ou bien (b < a)
3. Transitivité
∀a, b, c ∈ E, ((a < b) ∧ (b < c)) ⇒ (a < c)
&
c jt . . . . . . . 99/344
enib %
&
c jt . . . . . . 100/344
enib %
'
$
Tables associatives
STL
set
'
Définitions
set.h
typedef
typedef
typedef
typedef
typedef
typedef
typedef
typedef
typedef
typedef
template <class Key, class Compare> class set
typedef
typedef
typedef
typedef
typedef
Key key type ;
Key value type ;
Compare key compare ;
Compare value compare ;
rb tree<key type, value type,
ident<value type, key type>, key compare> rep type ;
&
'
c jt . . . . . . 101/344
enib set<Key,Compare>
%
&
$
'
Key key type ;
Key value type ;
Compare key compare ;
Compare value compare ;
rep type : :const reference reference ;
rep type : :const reference const reference ;
rep type : :const iterator iterator ;
rep type : :const iterator const iterator ;
rep type : :const reverse iterator reverse iterator ;
rep type : :const reverse iterator
const reverse iterator ;
typedef rep type : :size type size type ;
typedef rep type : :difference type difference type ;
c jt . . . . . . 102/344
enib %
$
set<Key,Compare>
Inspecteurs
Allocations
key compare key comp(void) const ;
value compare value comp(void) const ;
bool empty(void) const ;
size type size(void) const ;
size type max size(void) const ;
size type count(const key type& x) const ;
iterator find(const key type& x) const ;
iterator lower bound(const key type& x) const ;
iterator upper bound(const key type& x) const ;
pair<iterator, iterator>
equal range(const key type& x) const ;
set(const Compare& comp = Compare()) ;
set(const value type* first, const value type* last,
const Compare& comp = Compare()) ;
set(const set<Key, Compare>& x) ;
set<Key, Compare>& operator=(const set<Key, Compare>& x) ;
~set(void) ;
&
$
set<Key,Compare>
c jt . . . . . . 103/344
enib %
&
c jt . . . . . . 104/344
enib %
'
$
set<Key,Compare>
'
$
set<Key,Compare>
Insertions et suppressions
Itérateurs
iterator begin(void) const ;
iterator end(void) const ;
reverse iterator rbegin(void) const ;
reverse iterator rend(void) const ;
pair<iterator, bool> insert(const value type& x) ;
iterator insert(iterator position, const value type& x) ;
void insert(const value type* first, const value type* last) ;
void erase(iterator position) ;
size type erase(const key type& x) ;
void erase(iterator first, iterator last) ;
&
'
c jt . . . . . . 105/344
enib set<Key,Compare>
%
&
$
'
c jt . . . . . . 106/344
enib $
Tables associatives
Exemple d’utilisation de la classe set
%
Les tas ordonnés
Un tas ordonné est un ensemble ordonné avec répétition éventuelle
des éléments.
set<int, less<int> > s ;
pair<set<int, less<int> > : :const iterator, bool> p ;
p = s.insert(42) ;
if(p.second)
cout << "Inserted new element " << *(p.first) << endl ;
else
cout << "Existing element = " << *(p.first) << endl ;
1. Multiplicité des éléments
∀a, b ∈ E, (a 6= b) ou bien (a = b)
2. Eléments comparables
∀a, b ∈ E, (a < b) ou bien (a = b) ou bien (b < a)
p = s.insert(42) ;
if(p.second) cout << "Inserted new element" << endl ;
else cout << "Existing element" << endl ;
3. Transitivité
∀a, b, c ∈ E, ((a < b) ∧ (b < c)) ⇒ (a < c)
&
c jt . . . . . . 107/344
enib %
&
c jt . . . . . . 108/344
enib %
'
$
Tables associatives
multiset
STL
'
Définitions
multiset.h
typedef
typedef
typedef
typedef
typedef
typedef
typedef
typedef
template <class Key, class Compare> class multiset ;
typedef Key key type ;
typedef Key value type ;
typedef Compare key compare ;
typedef Compare value compare ;
typedef rb tree<key type, value type,
ident<value type, key type>, key compare> rep type ;
&
'
&
$
multiset
c jt . . . . . . 109/344
enib multiset
%
&
$
'
rep
rep
rep
rep
rep
rep
rep
rep
type
type
type
type
type
type
type
type
:
:
:
:
:
:
:
:
:size type size type ;
:difference type difference type ;
:const reference reference ;
:const reference const reference ;
:const iterator iterator ;
:const iterator const iterator ;
:const reverse iterator reverse iterator ;
:const reverse iterator
const reverse iterator ;
c jt . . . . . . 110/344
enib $
multiset
Allocations
Inspecteurs
multiset(const Compare& comp = Compare()) ;
multiset(const value type* first, const value type* last,
const Compare& comp = Compare()) ;
multiset(const multiset<Key, Compare>& x) ;
multiset<Key, Compare>&
operator=(const multiset<Key, Compare>& x) ;
key compare key comp(void) const ;
value compare value comp(void) const ;
bool empty(void) const ;
size type size(void) const ;
size type max size(void) const ;
iterator find(const key type& x) const ;
size type count(const key type& x) const ;
iterator lower bound(const key type& x) const ;
iterator upper bound(const key type& x) const ;
pair<iterator,iterator> equal range(const key type& x) const ;
c jt . . . . . . 111/344
enib %
&
%
c jt . . . . . . 112/344
enib %
'
$
multiset
'
$
multiset
Insertions et suppressions
Itérateurs
iterator begin(void) const ;
iterator end(void) const ;
reverse iterator rbegin(void) const ;
reverse iterator rend(void) const ;
iterator insert(const value type& x) ;
iterator insert(iterator position, const value type& x) ;
void insert(const value type* first, const value type* last) ;
void erase(iterator position) ;
size type erase(const key type& x) ;
void erase(iterator first, iterator last) ;
&
'
c jt . . . . . . 113/344
enib multiset<Key,Compare>
%
&
$
'
c jt . . . . . . 114/344
enib Les dictionnaires
Un dictionnaire est un ensemble ordonné de clés (les mots du dictionnaire) auxquelles sont associées des valeurs (les définitions du
dictionnaire).
// bool less than(int a, int b) { return a < b ; }
// bool greater than(int a, int b) { return a > b ; }
typedef pointer to binary function<int, int, bool> fn type ;
typedef multiset<int, fn type> mset ;
int array[] = { 3, 6, 1, 9 } ;
fn type f1(less than), f2(greater than) ;
mset s1(array, array + 4, f1), s2(array, array + 4, f2) ;
&
mset : :const iterator i = s1.begin() ;
while(i != s1.end()) cout << *i++ << endl ;
i = s2.begin() ;
while(i != s2.end()) cout << *i++ << endl ;
c jt . . . . . . 115/344
enib $
Tables associatives
Exemple d’utilisation de la classe multiset
%
1. Unicité des clés
2. Association clé–valeur : une clé, une valeur
%
&
c jt . . . . . . 116/344
enib %
'
$
Tables associatives
STL
map
'
Définitions
map.h
typedef
typedef
typedef
typedef
typedef
typedef
typedef
Key key type ;
pair<const Key, T> value type ;
Compare key compare ;
rb tree<key type, value type,
select1st<value type, key type>, key compare> rep type ;
&
'
c jt . . . . . . 117/344
enib map<Key,T,Compare>
%
&
$
'
type
type
type
type
type
type
type
:
:
:
:
:
:
:
c jt . . . . . . 118/344
enib %
$
map<Key,T,Compare>
Inspecteurs
Allocations
key compare key comp(void) const ;
value compare value comp(void) const ;
bool empty(void) const ;
size type size(void) const ;
size type max size(void) const ;
size type count(const key type& x) const ;
Allocator<T> : :reference operator[](const key type& k) ;
map(const Compare& comp = Compare()) ;
map(const value type* first, const value type* last,
const Compare& comp = Compare()) ;
map(const map<Key, T, Compare>& x) ;
map<Key,T,Compare>& operator=(const map<Key,T,Compare>& x) ;
&
rep
rep
rep
rep
rep
rep
rep
:pointer pointer ;
:reference reference ;
:const reference const reference ;
:iterator iterator ;
:const iterator const iterator ;
:reverse iterator reverse iterator ;
:const reverse iterator
const reverse iterator ;
typedef rep type : :size type size type ;
typedef rep type : :difference type difference type ;
template <class Key, class T, class Compare> class map
typedef
typedef
typedef
typedef
$
map<Key,T,Compare>
c jt . . . . . . 119/344
enib %
&
c jt . . . . . . 120/344
enib %
'
$
map<Key,T,Compare>
'
Inspecteurs
Itérateurs
iterator find(const key type& x) ;
const iterator find(const key type& x) const ;
iterator lower bound(const key type& x) ;
const iterator lower bound(const key type& x) const ;
iterator upper bound(const key type& x) ;
const iterator upper bound(const key type& x) const ;
pair<iterator, iterator> equal range(const key type& x) ;
pair<const iterator, const iterator>
equal range(const key type& x) const ;
&
'
c jt . . . . . . 121/344
enib map<Key,T,Compare>
iterator begin(void) ;
const iterator begin(void) const ;
iterator end(void) ;
const iterator end(void) const ;
reverse iterator rbegin(void) ;
const reverse iterator rbegin(void) const ;
reverse iterator rend(void) ;
const reverse iterator rend(void) const ;
%
&
$
'
c jt . . . . . . 122/344
enib Exemple d’utilisation de la classe map
pair<iterator, bool> insert(const value type& x) ;
iterator insert(iterator position, const value type& x) ;
void insert(const value type* first, const value type* last) ;
map<char, int, less<char> > m ;
m[’l’] = 50 ; m[’x’] = 20 ; m[’v’] = 5 ; m[’i’] = 1 ;
cout << m[’x’] << endl ; m[’x’] = 10 ; cout << m[’x’] << endl ;
cout << "m[’z’] = " << m[’z’] << endl ;
cout << "m.count(’z’) = " << m.count(’z’) << endl ;
c jt . . . . . . 123/344
enib %
&
%
$
map<Key,T,Compare>
Insertions et suppressions
void erase(iterator position) ;
size type erase(const key type& x) ;
void erase(iterator first, iterator last) ;
&
$
map<Key,T,Compare>
pair<maptype : :iterator, bool> p ;
p = m.insert(pair<const char, int>(’c’, 100)) ;
if(p.second) cout << "First insertion successful" << endl ;
p = m.insert(pair<const char, int>(’c’, 100)) ;
if(p.second) cout << "Second insertion successful" << endl ;
else cout << (*(p.first)).first << ’,’
<< (*(p.first)).second << endl ;
c jt . . . . . . 124/344
enib %
'
$
Tables associatives
'
Les encyclopédies
multimap
Une encyclopédie est un tas ordonné de clés (les entrées de l’encyclopédie) auxquelles sont associées des valeurs (les informations de
l’encyclopédie).
$
Tables associatives
STL
multimap.h
template <class Key, class T, class Compare> class multimap ;
1. Multiplicité des clés
2. Association clé–valeur : une clé, une valeur
typedef Key key type ;
typedef pair<const Key, T> value type ;
typedef Compare key compare ;
typedef rb tree<key type, value type,
select1st<value type, key type>, key compare> rep type ;
&
'
c jt . . . . . . 125/344
enib multimap
%
&
$
'
Définitions
typedef
typedef
typedef
typedef
typedef
typedef
typedef
typedef
&
rep
rep
rep
rep
rep
rep
rep
rep
type
type
type
type
type
type
type
type
:
:
:
:
:
:
:
:
c jt . . . . . . 126/344
enib %
$
multimap
Allocations
:size type size type ;
:difference type difference type ;
:reference reference ;
:const reference const reference ;
:iterator iterator ;
:const iterator const iterator ;
:reverse iterator reverse iterator ;
:const reverse iterator
const reverse iterator ;
c jt . . . . . . 127/344
enib multimap(const Compare& comp = Compare()) ;
multimap(const value type* first, const value type* last,
const Compare& comp = Compare()) ;
multimap(const multimap<Key, T, Compare>& x) ;
multimap<Key,T,Compare>&
operator=(const multimap<Key,T,Compare>& x) ;
%
&
c jt . . . . . . 128/344
enib %
'
$
multimap
'
Inspecteurs
Inspecteurs
key compare key comp(void) const ;
value compare value comp(void) const ;
bool empty(void) const ;
size type size(void) const ;
size type max size(void) const ;
&
'
iterator find(const key type& x) ;
const iterator find(const key type& x) const ;
size type count(const key type& x) const ;
iterator lower bound(const key type& x) ;
const iterator lower bound(const key type& x) const ;
iterator upper bound(const key type& x) ;
const iterator upper bound(const key type& x) const ;
pair<iterator, iterator> equal range(const key type& x) ;
pair<const iterator, const iterator>
equal range(const key type& x) const ;
c jt . . . . . . 129/344
enib multimap
%
&
$
'
c jt . . . . . . 130/344
enib %
$
multimap
Insertions et suppressions
Itérateurs
iterator begin(void) ;
const iterator begin(void) const ;
iterator end(void) ;
const iterator end(void) const ;
reverse iterator rbegin(void) ;
const reverse iterator rbegin(void) const ;
reverse iterator rend(void) ;
const reverse iterator rend(void) const ;
&
$
multimap
iterator insert(const value type& x) ;
iterator insert(iterator position, const value type& x) ;
void insert(const value type* first, const value type* last) ;
void erase(iterator position) ;
size type erase(const key type& x) ;
void erase(iterator first, iterator last) ;
c jt . . . . . . 131/344
enib %
&
c jt . . . . . . 132/344
enib %
'
$
multimap
'
Adaptateurs
Exemple d’utilisation de la classe multimap
Les adaptateurs
multimap<char, int, less<char> > m ;
cout << m.count (’X’) << endl ;
m.insert(pair<const char, int>(’X’, 10)) ;
cout << m.count(’X’) << endl ;
m.insert(’X’, 20) ;
cout << m.count(’X’) << endl ;
m.insert(’Y’, 32) ;
multimap<char, int, less<char> > : :iterator i =
m.find(’X’) ;
while(i != m.end())
cout << (*i).first << ’,’ << (*i++).second << endl ;
cout << "Erased " << m.erase(’X’) << " items" << endl ;
&
'
c jt . . . . . . 133/344
enib Adaptateurs
$
Standard Template Library
1. stack<Container> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
2. queue<Container> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
3. priority queue<Container> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
%
&
$
'
Même implémentation, interfaces différentes
c jt . . . . . . 134/344
enib $
Adaptateurs
stack
%
STL
stack.h
container<T>
stack< container<T> >
PP
PP
PP
PP
PP
PP
PP
PP
P
Last In, First Out
queue< container<T> >
priority queue< container<T> >
template <class Container> class stack ;
typedef Container : :value type value type ;
typedef Container : :size type size type ;
&
c jt . . . . . . 135/344
enib %
&
c jt . . . . . . 136/344
enib %
'
$
stack<Container>
'
Interface publique
Exemple d’utilisation : stack
stack<list<int> > s ;
bool empty(void) const ;
size type size(void) const ;
value type& top(void) ;
const value type& top(void) const ;
void push(const value type& x) ;
void pop(void) ;
s.push(42) ; s.push(101) ; s.push(69) ;
while( !s.empty()) {
cout << s.top() << endl ;
s.pop() ;
}
friend bool operator==(const stack<Container>& x,
const stack<Container>& y) ;
friend bool operator<(const stack<Container>& x,
const stack<Container>& y) ;
&
c jt . . . . . . 137/344
enib '
Adaptateurs
queue
STL
%
&
$
'
%
$
queue<Container>
bool empty(void) const ;
size type size(void) const ;
value type& front(void) ;
const value type& front(void) const ;
value type& back(void) ;
const value type& back(void) const ;
void push(const value type& x) ;
void pop(void) ;
template <class Container> class queue ;
typedef Container : :value type value type ;
typedef Container : :size type size type ;
c jt . . . . . . 139/344
enib c jt . . . . . . 138/344
enib Interface publique
stack.h
First In, First Out
&
$
stack<Container>
%
&
friend bool operator==(const queue<Container>& x,
const queue<Container>& y) ;
friend bool operator<(const queue<Container>& x,
const queue<Container>& y) ;
c jt . . . . . . 140/344
enib %
'
$
queue<Container>
'
Exemple d’utilisation : queue
$
Adaptateurs
priority queue
STL
stack.h
queue<list<int> > q ;
q.push(42) ; q.push(101) ; q.push(69) ;
while( !q.empty()) {
cout << q.front() << endl ;
q.pop() ;
}
template <class Container> class priority queue ;
typedef Container : :value type value type ;
typedef Container : :size type size type ;
&
'
c jt . . . . . . 141/344
enib priority queue
%
&
$
'
Interface publique
%
$
priority queue
Exemple d’utilisation : priority queue
priority queue<deque<int>, less<int> > q ;
priority queue(const Compare& x = Compare()) ;
priority queue(const value type* first,
const value type* last, const Compare& x = Compare()) ;
bool empty(void) const ;
size type size(void) const ;
value type& top(void) ;
const value type& top(void) const ;
void push(const value type& x) ;
void pop(void) ;
&
c jt . . . . . . 142/344
enib c jt . . . . . . 143/344
enib q.push(42) ; q.push(101) ; q.push(69) ;
while( !q.empty()) {
cout << q.top() << endl ;
q.pop() ;
}
%
&
c jt . . . . . . 144/344
enib %
'
$
Standard Template Library
'
$
Calculs
Les algorithmes génériques
Accumulateur
Les algorithmes génériques
int array[] = { 1, 3, 6, 6, 8, 12, 12, 15, 17, 6 } ;
int* pointer = &array[3] ;
int n0 = 2, n = n0 ;
1. Calculs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
2. Comparaisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
3. Manipulations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
while(pointer != &array[8]) n += *pointer++ ;
4. Allocations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
5. Ensembles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
if(pointer == &array[8]) cout << (n - n0) << endl ;
6. Recherches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
&
'
c jt . . . . . . 145/344
enib Calculs
accumulate (1)
STL
%
&
$
'
c jt . . . . . . 147/344
enib %
$
Calculs
Exemple d’utilisation : accumulate (1)
algo.h
template <class InputIterator, class T>
T
accumulate(InputIterator first, InputIterator last, T init) {
while(first != last) init = init + *first++ ;
return init ;
}
&
c jt . . . . . . 146/344
enib vector<int> v(5) ;
for(int i = 0 ; i < v.size() ; i++) v[i] = i ;
cout << accumulate(v.begin(), v.end(), 0) << endl ;
%
&
c jt . . . . . . 148/344
enib %
'
$
Calculs
'
Accumulateur généralisé
$
Calculs
accumulate (2)
STL
algo.h
template <class InputIterator, class T,
class BinaryOperation>
T
accumulate(InputIterator first, InputIterator last, T init,
BinaryOperation operation) {
while(first != last) init = operation(init, *first++) ;
return init ;
}
/* int plus(int x, int y) { return x + y ; } */
int array[] = { 1, 3, 6, 6, 8, 12, 12, 15, 17, 6 } ;
int* pointer = &array[3] ;
int n0 = 2, n = n0 ;
int (*function)(int,int) = plus ;
while(pointer != &array[8]) n = function(n,*pointer++) ;
if(pointer == &array[8]) cout << (n - n0) << endl ;
&
'
c jt . . . . . . 149/344
enib Calculs
%
&
$
'
Exemple d’utilisation : accumulate (2)
c jt . . . . . . 150/344
enib %
$
Calculs
Produit scalaire
/* int mult(int x, int y) { return x * y ; } */
int array1[] = { 1, 3, 6, 6, 8, 12, 12, 15, 17, 6 } ;
int array2[] = { 6, 8, 12, 12, 14, 17, 6, 1, 3, 6 } ;
int* pointer1 = &array1[3] ;
int* pointer2 = &array2[1] ;
int n0 = 2, n = n0 ;
vector<int> v(5) ;
for(int i = 0 ; i < v.size() ; i++) v[i] = i + 1 ;
cout << accumulate(v.begin(), v.end(), 1, mult) << endl ;
while(pointer1 != &array1[8]) n += *pointer1++ * *pointer2++ ;
if(pointer1 == &array1[8]) cout << (n - n0) << endl ;
&
c jt . . . . . . 151/344
enib %
&
c jt . . . . . . 152/344
enib %
'
$
Calculs
inner product (1)
STL
'
Exemple d’utilisation : inner product (1)
algo.h
template <class InputIterator1, class InputIterator2,
class T>
T
inner product(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, T init) {
while(first1 != last1)
init = init + (*first1++ * *first2++) ;
return init ;
}
&
c jt . . . . . . 153/344
enib '
Calculs
vector<int> v1(5), v2(5) ;
for(int i = 0 ; i < v1.size() ; i++) v1[i] = i ;
for(int j = 0 ; j < v2.size() ; j++) v2[j] = j ;
cout << inner product(v1.begin(), v1.end(), v2.begin(), 0)
<< endl ;
%
&
$
'
Produit scalaire généralisé
array1[] = { 1, 3, 6, 6, 8, 12, 12, 15, 17, 6 } ;
array2[] = { 6, 8, 12, 12, 14, 17, 6, 1, 3, 6 } ;
*pointer1 = &array1[3], *pointer2 = &array2[1] ;
n0 = 2, n = n0 ;
(*function1)(int,int) = plus ;
(*function2)(int,int) = times ;
c jt . . . . . . 155/344
enib %
$
Calculs
STL
algo.h
template <class InputIterator1, class InputIterator2,
class T,
class BinaryOperation1, class BinaryOperation2>
T
inner product(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, T init,
BinaryOperation1 op1, BinaryOperation2 op2) {
while(first1 != last1)
init = op1(init, op2(*first1++, *first2++)) ;
return init ;
}
while(pointer1 != &array1[8])
n = function1(n,function2(*pointer1++,*pointer2++)) ;
&
c jt . . . . . . 154/344
enib inner product (2)
/* int plus(int x, int y) { return x + y ; } */
/* int times(int x, int y) { return x * y ; } */
int
int
int
int
int
int
$
Calculs
%
&
c jt . . . . . . 156/344
enib %
'
$
Calculs
'
$
Calculs
Exemple d’utilisation : inner product (2)
Somme partielle
int array1[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } ;
int array2[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } ;
int* pointer = &array1[0] ;
int* result = &array2[0] ;
/* int plus(int x, int y) { return x + y ; } */
/* int times(int x, int y) { return x * y ; } */
vector<int> v1(5), v2(5) ;
for(int i = 0 ; i < v1.size() ; i++) v1[i] = i ;
for(int j = 0 ; j < v2.size() ; j++) v2[j] = j ;
int value = *result = *pointer ;
while(++pointer != &array1[8]) {
value += *pointer ; *++result = value ;
}
cout << inner product(v1.begin(), v1.end(), v2.begin(), 0,
plus, mult)
<< endl ;
result = &array2[0] ;
while(result != &array2[10]) cout << *result++ << endl ;
&
'
c jt . . . . . . 157/344
enib Calculs
partial sum (1)
STL
%
&
$
'
c jt . . . . . . 159/344
enib %
$
Calculs
Exemple d’utilisation : partial sum (1)
algo.h
template <class InputIterator, class OutputIterator>
OutputIterator
partial sum(InputIterator first, InputIterator last,
OutputIterator result) {
if(first == last) return result ;
T value = *result = *first ;
while(++first != last) {
value = value + *first ;
*++result = value ;
}
return ++result ;
}
&
c jt . . . . . . 158/344
enib vector<int> v1(5) ;
for(int i = 0 ; i < v1.size() ; i++) v1[i] = i ;
vector<int> v2(v1.size()) ;
partial sum(v1.begin(), v1.end(), v2.begin()) ;
ostream iterator<int> iter(cout," ") ;
copy(v1.begin(), v1.end(), iter) ; cout << endl ;
copy(v2.begin(), v2.end(), iter) ; cout << endl ;
%
&
c jt . . . . . . 160/344
enib %
'
$
Calculs
'
Somme partielle généralisée
partial sum (2)
/* int plus(int x, int y) { return x + y ; } */
int array1[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } ;
int array2[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } ;
int* pointer = &array1[0] ; int* result = &array2[0] ;
int (*operation)(int,int) = plus ;
int value = *result = *pointer ;
while(++pointer != &array1[8]) {
value = operation(value,*pointer) ;
*++result = value ;
}
&
'
c jt . . . . . . 161/344
enib Calculs
%
&
$
'
Exemple d’utilisation : partial sum (2)
$
Calculs
STL
algo.h
template <class InputIterator, class OutputIterator,
class BinaryOperation>
OutputIterator
partial sum(InputIterator first, InputIterator last,
OutputIterator result, BinaryOperation operation) {
if(first == last) return result ;
T value = *result = *first ;
while(++first != last) {
value = operation(value,*first) ;
*++result = value ;
}
return ++result ;
}
c jt . . . . . . 162/344
enib %
$
Calculs
Différences
vector<int> v1(5) ;
for(int i = 0 ; i < v1.size() ; i++) v1[i] = i ;
vector<int> v2(v1.size()) ;
int array1[] = { 1, 2, 5, 3, 8 } ;
int array2[] = { 0, 0, 0, 0, 0 } ;
int* pointer = &array1[0] ; int* result = &array2[0] ;
partial sum(v1.begin(), v1.end(), v2.begin(), times<int>()) ;
int value = *result = *pointer ;
while(++pointer != &array1[5]) {
int tmp = *pointer ;
*++result = tmp - value ;
value = tmp ;
}
ostream iterator<int> iter(cout," ") ;
copy(v1.begin(), v1.end(), iter) ; cout << endl ;
copy(v2.begin(), v2.end(), iter) ; cout << endl ;
for(int i = 0 ; i < 5 ; i++) cout << array2[i] << endl ;
&
c jt . . . . . . 163/344
enib %
&
c jt . . . . . . 164/344
enib %
'
$
Calculs
adjacent difference (1)
&
'
STL
'
Exemple d’utilisation : adjacent difference (1)
algo.h
template <class InputIterator, class OutputIterator>
OutputIterator
adjacent difference(InputIterator first, InputIterator last,
OutputIterator result) {
if(first == last) return result ;
T value = *result = *first ;
while(++first != last) {
T tmp = *first ;
*++result = tmp - value ;
value = tmp ;
}
return ++result ;
}
c jt . . . . . . 165/344
enib Calculs
vector<int> v1(10) ;
for(int i = 0 ; i < v1.size() ; i++) v1[i] = i + 1 ;
vector<int> v2(v1.size()) ;
adjacent difference(v1.begin(), v1.end(), v2.begin()) ;
ostream iterator<int> iter(cout, " ") ;
copy(v1.begin(), v1.end(), iter) ; cout << endl ;
copy(v2.begin(), v2.end(), iter) ; cout << endl ;
%
&
$
'
Différences généralisées
/* int moins(int x, int y) { return x - y ; } */
int array1[] = { 1, 2, 5, 3, 8 } ;
int array2[] = { 0, 0, 0, 0, 0 } ;
int* pointer = &array1[0] ; int* result = &array2[0] ;
int (*operation)(int,int) = moins ;
&
c jt . . . . . . 166/344
enib c jt . . . . . . 167/344
enib %
&
%
$
Calculs
adjacent difference (2)
int value = *result = *pointer ;
while(++pointer != &array1[5]) {
int tmp = *pointer ;
*++result = operation(tmp,value) ;
value = tmp ;
}
$
Calculs
STL
algo.h
template <class InputIterator, class OutputIterator,
class BinaryOperation>
OutputIterator
adjacent difference(InputIterator first, InputIterator last,
OutputIterator result, BinaryOperation operation) {
if(first == last) return result ;
T value = *result = *first ;
while(++first != last) {
T tmp = *first ; *++result = operation(tmp,value) ;
value = tmp ;
}
return ++result ;
}
c jt . . . . . . 168/344
enib %
'
$
Calculs
'
Exemple d’utilisation : adjacent difference (2)
template <class T>
bool operator>(const T& x, const T& y) { return y < x ; }
adjacent difference(v1.begin(), v1.end(), v2.begin(), mult) ;
template <class T>
bool operator<=(const T& x, const T& y) { return !(y < x) ; }
ostream iterator<int> iter(cout, " ") ;
copy(v1.begin(), v1.end(), iter) ; cout << endl ;
copy(v2.begin(), v2.end(), iter) ; cout << endl ;
'
Comparaisons
function.h
template <class T>
bool operator !=(const T& x, const T& y) { return !(x == y) ; }
vector<int> v1(10) ;
for(int i = 0 ; i < v1.size() ; i++) v1[i] = i + 1 ;
vector<int> v2(v1.size()) ;
c jt . . . . . . 169/344
enib STL
!= , > , <= , >=
/* int mult(int a, int b) { return a * b ; } */
&
$
Comparaisons
template <class T>
bool operator>=(const T& x, const T& y) { return !(x < y) ; }
%
&
$
'
Exemple d’utilisation : != , > , <= , >=
c jt . . . . . . 170/344
enib %
$
Comparaisons
Maximum de 2 éléments
/* int less(int x, int y) { return x < y ; } */
int x, y ;
int max1, max2 ;
int (*compare)(int,int) = less ;
max1 = x < y ? y : x ;
max2 = compare(x,y) ? y : x ;
&
c jt . . . . . . 171/344
enib %
&
c jt . . . . . . 172/344
enib %
'
$
Comparaisons
max (1),(2)
STL
'
$
Comparaisons
Exemple d’utilisation : max (1),(2)
algobase.h
template <class T>
const T&
max(const T& x, const T& y) { return x < y ? y : x ; }
template <class T, class Compare>
const T&
max(const T& x, const T& b, Compare compare) {
return compare(x, y) ? y : x ;
}
&
'
c jt . . . . . . 173/344
enib Comparaisons
%
&
$
'
Maximum de n éléments
STL
algo.h
template <class InputIterator>
InputIterator
max element(InputIterator first, InputIterator last) {
if (first == last) return first ;
InputIterator result = first ;
while(++first != last)
if(*result < *first) result = first ;
return result ;
}
int array[] = { 1, 3, 6, 6, 8, 12, 12, 15, 17, 6 } ;
int* pointer = &array[0] ;
int max1 = *pointer, max2 = *pointer ;
int (*compare)(int,int) = less ;
while(++pointer != &array[8]) {
if(max1 < *pointer) max1 = *pointer ;
if(compare(max2,*pointer) max2 = *pointer ;
}
c jt . . . . . . 175/344
enib %
$
Comparaisons
max element (1)
/* int less(int x, int y) { return x < y ; } */
&
c jt . . . . . . 174/344
enib %
&
c jt . . . . . . 176/344
enib %
'
$
Comparaisons
'
Exemple d’utilisation : max element (1)
$
Comparaisons
STL
max element (2)
algo.h
template <class InputIterator, class Compare>
InputIterator
max element(InputIterator first, InputIterator last,
Compare compare) {
if (first == last) return first ;
InputIterator result = first ;
while(++first != last)
if(compare(*result,*first)) result = first ;
return result ;
}
&
'
c jt . . . . . . 177/344
enib Comparaisons
%
&
$
'
Exemple d’utilisation : max element (2)
c jt . . . . . . 178/344
enib %
$
Comparaisons
Minimum de 2 éléments
/* int less(int x, int y) { return x < y ; } */
int x, y ;
int min1, min2 ;
int (*compare)(int,int) = less ;
min1 = x < y ? x : y ;
min2 = compare(x,y) ? x : y ;
&
c jt . . . . . . 179/344
enib %
&
c jt . . . . . . 180/344
enib %
'
$
Comparaisons
min (1),(2)
STL
'
$
Comparaisons
Exemple d’utilisation : min (1),(2)
algobase.h
template <class T>
const T&
min(const T& x, const T& y) { return x < y ? x : y ; }
template <class T, class Compare>
const T&
min(const T& x, const T& b, Compare compare) {
return compare(x, y) ? x : y ;
}
&
'
c jt . . . . . . 181/344
enib Comparaisons
%
&
$
'
Minimum de n éléments
STL
algo.h
template <class InputIterator>
InputIterator
min element(InputIterator first, InputIterator last) {
if (first == last) return first ;
InputIterator result = first ;
while(++first != last)
if(*first < *result) result = first ;
return result ;
}
int array[] = { 1, 3, 6, 6, 8, 12, 12, 15, 17, 6 } ;
int* pointer = &array[0] ;
int min1 = *pointer, min2 = *pointer ;
int (*compare)(int,int) = less ;
while(++pointer != &array[8]) {
if(*pointer < min1) min1 = *pointer ;
if(compare(*pointer,min2) min2 = *pointer ;
}
c jt . . . . . . 183/344
enib %
$
Comparaisons
min element (1)
/* int less(int x, int y) { return x < y ; } */
&
c jt . . . . . . 182/344
enib %
&
c jt . . . . . . 184/344
enib %
'
$
Comparaisons
'
Exemple d’utilisation : min element (1)
$
Comparaisons
min element (2)
STL
algo.h
template <class InputIterator, class Compare>
InputIterator
min element(InputIterator first, InputIterator last,
Compare compare) {
if (first == last) return first ;
InputIterator result = first ;
while(++first != last)
if(compare(*first,*result)) result = first ;
return result ;
}
&
'
c jt . . . . . . 185/344
enib Comparaisons
%
&
$
'
Exemple d’utilisation : min element (2)
c jt . . . . . . 186/344
enib %
$
Comparaisons
Différence entre 2 séquences
int array1[] = { 1, 3, 6, 6, 8, 12, 12, 15, 17, 6 } ;
int array2[] = { 6, 8, 12, 12, 14, 17, 6, 1, 3, 6 } ;
int* pointer1 = &array1[3] ;
int* pointer2 = &array2[0] ;
while(pointer1 != &array1[8] && *pointer1 == *pointer2) {
++pointer1 ;
++pointer2 ;
}
if(pointer1 == &array1[8]) cout << "no mismatch" << endl ;
&
c jt . . . . . . 187/344
enib %
&
c jt . . . . . . 188/344
enib %
'
$
Comparaisons
mismatch (1)
STL
'
$
Comparaisons
Exemple d’utilisation : mismatch (1)
algo.h
template <class InputIterator1, class InputIterator2>
pair<InputIterator1,InputIterator2>
mismatch(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2) {
while(first1 != last1 && *first1 == *first2) {
++first1 ;
++first2 ;
}
return pair<InputIterator1,InputIterator2>(first1,first2) ;
}
&
'
c jt . . . . . . 189/344
enib Comparaisons
%
&
$
'
Différence généralisée
STL
algo.h
template <class InputIterator1, class InputIterator2,
class BinaryPredicate>
pair<InputIterator1,InputIterator2>
mismatch(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, BinaryPredicate predicate) {
while(first1 != last1 && predicate(*first1,*first2)) {
++first1 ;
++first2 ;
}
return pair<InputIterator1,InputIterator2>(first1,first2) ;
}
int array1[] = { 1, 3, 6, 6, 8, 12, 12, 15, 17, 6 } ;
int array2[] = { 6, 8, 12, 12, 14, 17, 6, 1, 3, 6 } ;
int* pointer1 = &array1[3] ; int* pointer2 = &array2[0] ;
int (*predicate)(int,int) = equal ;
while(pointer1 != &array1[10] &&
predicate(*pointer1,*pointer2)) {
++pointer1 ; ++pointer2 ;
}
if(pointer1 == &array1[10]) cout << "no mismatch" << endl ;
c jt . . . . . . 191/344
enib %
$
Comparaisons
mismatch (2)
/* int equal(int x, int y) { return x == y ; } */
&
c jt . . . . . . 190/344
enib %
&
c jt . . . . . . 192/344
enib %
'
$
Comparaisons
'
$
Comparaisons
Exemple d’utilisation : mismatch (2)
Egalité de 2 séquences
int array1[] = { 1, 3, 6, 6, 8, 12, 12, 15, 17, 6 } ;
int array2[] = { 6, 8, 12, 12, 14, 17, 6, 1, 3, 6 } ;
int* pointer1 = &array1[3] ;
int* pointer2 = &array2[0] ;
while(pointer1 != &array1[8] && *pointer1 == *pointer2) {
++pointer1 ;
++pointer2 ;
}
if(pointer1 != &array1[8]) cout << "not equal" << endl ;
&
'
c jt . . . . . . 193/344
enib Comparaisons
equal (1)
STL
%
&
$
'
c jt . . . . . . 194/344
enib %
$
Comparaisons
Exemple d’utilisation : equal (1)
algo.h
template <class InputIterator1, class InputIterator2>
bool
equal(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2) {
return mismatch(first1,last1,first2).first == last1 ;
}
&
c jt . . . . . . 195/344
enib %
&
c jt . . . . . . 196/344
enib %
'
$
Comparaisons
'
Egalité généralisée
equal (2)
int array1[] = { 1, 3, 6, 6, 8, 12, 12, 15, 17, 6 } ;
int array2[] = { 6, 8, 12, 12, 14, 17, 6, 1, 3, 6 } ;
int* pointer1 = &array1[3] ; int* pointer2 = &array2[0] ;
int (*predicate)(int,int) = equal ;
while(pointer1 != &array1[10] &&
predicate(*pointer1,*pointer2)) {
++pointer1 ; ++pointer2 ;
}
if(pointer1 != &array1[10]) cout << "not equal" << endl ;
'
c jt . . . . . . 197/344
enib Comparaisons
STL
algo.h
template <class InputIterator1, class InputIterator2,
class BinaryPredicate>
bool
equal(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, BinaryPredicate predicate) {
return
mismatch(first1,last1,first2,predicate).first == last1 ;
}
/* int equal(int x, int y) { return x == y ; } */
&
$
Comparaisons
%
&
$
'
Exemple d’utilisation : equal (2)
c jt . . . . . . 198/344
enib %
$
Comparaisons
Comparaison lexicographique de 2 séquences
int array1[] = { 1, 3, 6, 6, 8, 12, 12, 15, 17, 6 } ;
int array2[] = { 6, 8, 12, 12, 14, 17, 6, 1, 3, 6 } ;
int* pointer1 = &array1[3] ; int* pointer2 = &array2[0] ;
int result = -1 ;
while(pointer1 != &array1[8] && pointer2 != &array2[9]) {
if(*pointer1 < *pointer2) { result = 1 ; break ; }
if(*pointer2++ < *pointer1++) { result = 0 ; break ; }
}
if(result == -1)
result = (pointer1 == &array1[8] &&
pointer2 != &array2[9]) ;
&
c jt . . . . . . 199/344
enib %
&
c jt . . . . . . 200/344
enib %
'
$
Comparaisons
lexicographical compare (1) STL
'
$
Comparaisons
Exemple d’utilisation : lexicographical compare (1)
algo.h
template <class InputIterator1, class InputIterator2>
bool
lexicographical compare(
InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2) {
while(first1 != last1 && first2 != last2) {
if(*first1 < *first2) return true ;
if(*first2++ < *first1++) return false ;
}
return (first1 == last1 && first2 != last2 ;)
}
&
'
c jt . . . . . . 201/344
enib Comparaisons
%
&
$
'
Comparaison lexicographique généralisée
&
c jt . . . . . . 203/344
enib %
&
%
$
Comparaisons
lexicographical compare (2) STL
/* int less(int x, int y) { return x < y ; } */
int array1[] = { 1, 3, 6, 6, 8, 12, 12, 15, 17, 6 } ;
int array2[] = { 6, 8, 12, 12, 14, 17, 6, 1, 3, 6 } ;
int* pointer1 = &array1[3] ; int* pointer2 = &array2[0] ;
int (*compare)(int,int) = less ;
int res = -1 ;
while(pointer1 != &array1[8] && pointer2 != &array2[9]) {
if(compare(*pointer1,*pointer2)) { res = 1 ; break ; }
if(compare(*pointer2++,*pointer1++)) { res = 0 ; break ; }
}
if(res == -1)
res = (pointer1 == &array1[8] && pointer2 != &array2[9]) ;
c jt . . . . . . 202/344
enib algo.h
template <class InputIterator1, class InputIterator2,
class Compare>
bool
lexicographical compare(
InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
Compare compare) {
while(first1 != last1 && first2 != last2) {
if(compare(*first1,*first2)) return true ;
if(compare(*first2++,*first1++)) return false ;
}
return (first1 == last1 && first2 != last2 ;)
}
c jt . . . . . . 204/344
enib %
'
$
Comparaisons
'
$
Algorithmes génériques
Exemple d’utilisation : lexicographical compare (2)
Manipulations
for each ............
generate ............
generate n ..........
iter swap ...........
partition ...........
remove ..............
remove copy .........
remove copy if ......
remove if ...........
&
c jt . . . . . . 205/344
enib '
Manipulations
swap
STL
%
&
$
'
replace .............
replace copy ........
replace copy if .....
replace if ..........
swap .................
swap ranges .........
transform (1) ......
transform (2) ......
225
229
231
227
207
211
221
223
c jt . . . . . . 206/344
enib %
$
Manipulations
Exemple d’utilisation : swap
algobase.h
template <class T>
void
swap(T& a, T& b) {
T tmp = a ;
a = b;
b = tmp ;
}
&
214
216
219
209
241
237
233
235
239
int numbers[6] = { 0, 1, 2, 3, 4, 5 } ;
swap(numbers[0], numbers[3]) ;
for(int i = 0 ; i < 6 ; i++) cout << numbers[i] << ’ ’ ;
c jt . . . . . . 207/344
enib %
&
c jt . . . . . . 208/344
enib %
'
$
Manipulations
iter swap
STL
'
$
Manipulations
Exemple d’utilisation : iter swap
algo.h
template <class ForwardIterator1, class ForwardIterator2>
void
iter swap(ForwardIterator1 a, ForwardIterator2 b) {
iter swap(a, b, value type(a)) ;
}
int numbers[6] = { 0, 1, 2, 3, 4, 5 } ;
iter swap(numbers, numbers + 3) ;
for(int i = 0 ; i < 6 ; i++) cout << numbers[i] << ’ ’ ;
template <class ForwardIterator1, class ForwardIterator2,
class T>
void iter swap(ForwardIterator1 a, ForwardIterator2 b, T*) {
T tmp = *a ; *a = *b ; *b = tmp ;
}
&
'
c jt . . . . . . 209/344
enib Manipulations
swap ranges
STL
%
&
$
'
c jt . . . . . . 211/344
enib %
$
Manipulations
Exemple d’utilisation : swap ranges
algo.h
template <class ForwardIterator1, class ForwardIterator2>
ForwardIterator2
swap ranges(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2) {
while(first1 != last1) iter swap(first1++, first2++) ;
return first2 ;
}
&
c jt . . . . . . 210/344
enib char* word1 = "world !" ;
char* word2 = "Hello " ;
cout << word1 << word2 << endl ;
swap ranges(word1, word1 + : :strlen(word1), word2) ;
cout << word1 << word2 << endl ;
%
&
c jt . . . . . . 212/344
enib %
'
$
Manipulations
'
Application d’une fonction
$
Manipulations
for each
STL
algo.h
template <class InputIterator, class Function>
Function
for each(InputIterator first, InputIterator last,
Function function) {
while(first != last) function(*first++) ;
return function ;
}
/* void display(int x) { cout << x * x << ’ ’ ; } */
int array[] = { 1, 3, 5, 6, 8, 12, 12, 15, 17, 20 } ;
int* first = &array[3] ;
int* last = &array[8] ;
void (*function)(int) = display ;
while(first != last) function(*first++) ;
&
'
c jt . . . . . . 213/344
enib Manipulations
%
&
$
'
Exemple d’utilisation : for each
STL
algo.h
template <class ForwardIterator, class Generator>
void
generate(ForwardIterator first, ForwardIterator last,
Generator generator) {
while(first != last) *first++ = generator() ;
}
vector<int> v1(10) ;
for(int i = 0 ; i < v1.size() ; i++) v1[i] = i ;
for each(v1.begin(), v1.end(), display) ;
c jt . . . . . . 215/344
enib %
$
Manipulations
generate
/* void display(int x) { cout << x * x << ’ ’ ; } */
&
c jt . . . . . . 214/344
enib %
&
c jt . . . . . . 216/344
enib %
'
$
Manipulations
'
Exemple d’utilisation : generate
$
Manipulations
Exemple d’utilisation : generate (suite)
vector<int> v1(10) ;
Fibonacci generator ;
class Fibonacci {
private :
int v1, v2 ;
public :
Fibonacci(void) : v1(0), v2(1) {}
int operator()(void) {
int r = v1 + v2 ;
v1 = v2 ; v2 = r ;
return v1 ;
}
};
generate(v1.begin(), v1.end(), generator) ;
ostream iterator<int> iter(cout, " ") ;
copy(v1.begin(), v1.end(), iter) ;
... fin
à suivre ...
&
'
c jt . . . . . . 217/344
enib Manipulations
generate n
STL
%
&
$
'
c jt . . . . . . 219/344
enib %
$
Manipulations
Exemple d’utilisation : generate n
algo.h
template <class OutputIterator, class Size,
class Generator>
OutputIterator
generate n(OutputIterator first, Size n,
Generator generator) {
while(n-- > 0) *first++ = generator() ;
return first ;
}
&
c jt . . . . . . 218/344
enib vector<int> v1(10) ;
Fibonacci generator ;
generate n(v1.begin(), v1.size(), generator) ;
ostream iterator<int> iter(cout, " ") ;
copy(v1.begin(), v1.end(), iter) ;
%
&
c jt . . . . . . 220/344
enib %
'
$
Manipulations
transform (1)
STL
'
Exemple d’utilisation : transform (1)
algo.h
template <class InputIterator, class OutputIterator,
class UnaryOperation>
OutputIterator
transform(InputIterator first, InputIterator last,
OutputIterator result, UnaryOperation operation) {
while(first != last) *result++ = operation(*first++) ;
return result ;
}
&
'
c jt . . . . . . 221/344
enib Manipulations
transform (2)
STL
$
Manipulations
int negate int(int a) { return -a ; }
int numbers[6] = { -5, -1, 0, 1, 6, 11 } ;
int result[6] ;
transform(numbers, numbers + 6, result, negate int) ;
for(int i = 0 ; i < 6 ; i++) cout << result[i] << ’ ’ ;
%
&
$
'
c jt . . . . . . 222/344
enib %
$
Manipulations
Exemple d’utilisation : transform (2)
algo.h
template <class InputIterator1, class InputIterator2,
class OutputIterator, class BinaryOperation>
OutputIterator
transform(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, OutputIterator result,
BinaryOperation operation) {
while(first1 != last1)
*result++ = operation(*first1++, *first2++) ;
return result ;
}
char map char(char a, int b) { return char(a + b) ; }
int trans[] = {
-4, 4, -6, -6, -10, 0, 10, -6, 6, 0, -1, -77
};
char n[] = "Larry Mullen" ;
const unsigned int count = : :strlen(n) ;
ostream iterator<char> iter(cout) ;
transform(n, n + count, trans, iter, map char) ;
&
c jt . . . . . . 223/344
enib %
&
c jt . . . . . . 224/344
enib %
'
$
Manipulations
replace
STL
'
Exemple d’utilisation : replace
algo.h
template <class ForwardIterator, class T>
void
replace(ForwardIterator first, ForwardIterator last,
const T& old value, const T& new value) {
while(first != last) {
if(*first == old value) *first = new value ;
++first ;
}
}
&
'
c jt . . . . . . 225/344
enib Manipulations
replace if
STL
$
Manipulations
int numbers[6] = { 0, 1, 2, 0, 1, 2 } ;
replace(numbers, numbers + 6, 2, 42) ;
for(int i = 0 ; i < 6 ; i++) cout << numbers[i] << ’ ’ ;
%
&
$
'
c jt . . . . . . 226/344
enib %
$
Manipulations
Exemple d’utilisation : replace if
algo.h
template <class ForwardIterator, class Predicate, class T>
void
replace if(ForwardIterator first, ForwardIterator last,
Predicate predicate, const T& new value) {
while(first != last) {
if(predicate(*first)) *first = new value ;
++first ;
}
}
/* bool odd(int a) { return a % 2 ; } */
vector<int> v1(10) ;
for(int i = 0 ; i < v1.size() ; i++) {
v1[i] = i % 5 ; cout << v1[i] << ’ ’ ;
}
replace if(v1.begin(), v1.end(), odd, 42) ;
for(i = 0 ; i < v1.size() ; i++) cout << v1[i] << ’ ’ ;
&
c jt . . . . . . 227/344
enib %
&
c jt . . . . . . 228/344
enib %
'
$
Manipulations
replace copy
STL
'
Exemple d’utilisation : replace copy
algo.h
template <class InputIterator, class OutputIterator,
class T>
OutputIterator
replace copy(InputIterator first, InputIterator last,
OutputIterator result, const T& old value,
const T& new value) {
while(first != last) {
*result++ = *first == old value ? new value : *first ;
++first ;
}
return result ;
}
&
'
c jt . . . . . . 229/344
enib Manipulations
replace copy if
STL
int numbers[6] = { 0, 1, 2, 0, 1, 2 } ;
int result[6] = { 0, 0, 0, 0, 0, 0 } ;
replace copy(numbers, numbers + 6, result, 2, 42) ;
for(int i = 0 ; i < 6 ; i++) cout << result[i] << ’ ’ ;
%
&
$
'
c jt . . . . . . 231/344
enib c jt . . . . . . 230/344
enib %
$
Manipulations
Exemple d’utilisation : replace copy if
algo.h
template <class Iterator, class OutputIterator,
class Predicate, class T>
OutputIterator
replace copy if(Iterator first, Iterator last,
OutputIterator result, Predicate predicate,
const T& new value) {
while(first != last) {
*result++ = predicate(*first) ? new value : *first ;
++first ;
}
return result ;
}
&
$
Manipulations
/* bool odd(int a) { return a % 2 ; } */
vector<int> v1(10), v2(10) ;
for(int i = 0 ; i < v1.size() ; i++) v1[i] = i % 5 ;
ostream iterator<int> iter(cout, " ") ;
copy(v1.begin(), v1.end(), iter) ;
replace copy if(v1.begin(), v1.end(), v2.begin(), odd, 42) ;
copy(v1.begin(), v1.end(), iter) ;
copy(v2.begin(), v2.end(), iter) ;
%
&
c jt . . . . . . 232/344
enib %
'
$
Manipulations
remove copy
STL
'
Exemple d’utilisation : remove copy
algo.h
template <class InputIterator, class OutputIterator,
class T>
OutputIterator
remove copy(InputIterator first, InputIterator last,
OutputIterator result, const T& value) {
while(first != last) {
if(*first != value) *result++ = *first ;
++first ;
}
return result ;
}
&
'
c jt . . . . . . 233/344
enib Manipulations
remove copy if
STL
int numbers[6] = { 1, 2, 3, 1, 2, 3 } ;
int result[6] = { 0, 0, 0, 0, 0, 0 } ;
remove copy(numbers, numbers + 6, result, 2) ;
for(int i = 0 ; i < 6 ; i++) cout << result[i] << ’ ’ ;
%
&
$
'
c jt . . . . . . 235/344
enib c jt . . . . . . 234/344
enib %
$
Manipulations
Exemple d’utilisation : remove copy if
algo.h
template <class InputIterator, class OutputIterator,
class Predicate>
OutputIterator
remove copy if(InputIterator first, InputIterator last,
OutputIterator result, Predicate predicate) {
while(first != last) {
if( !predicate(*first)) *result++ = *first ;
++first ;
}
return result ;
}
&
$
Manipulations
/* bool odd(int a) { return a % 2 ; } */
int numbers[6] = { 1, 2, 3, 1, 2, 3 } ;
int result[6] = { 0, 0, 0, 0, 0, 0 } ;
remove copy if(numbers, numbers + 6, result, odd) ;
for(int i = 0 ; i < 6 ; i++) cout << result[i] << ’ ’ ;
%
&
c jt . . . . . . 236/344
enib %
'
$
Manipulations
remove
STL
'
Exemple d’utilisation : remove
algo.h
template <class ForwardIterator, class T>
ForwardIterator
remove(ForwardIterator first, ForwardIterator last,
const T& value) {
first = find(first, last, value) ;
ForwardIterator next = first ;
return first == last ? first :
remove copy(++next, last, first, value) ;
}
&
'
c jt . . . . . . 237/344
enib Manipulations
remove if
STL
int numbers[6] = { 1, 2, 3, 1, 2, 3 } ;
remove(numbers, numbers + 6, 1) ;
for(int i = 0 ; i < 6 ; i++) cout << numbers[i] << ’ ’ ;
%
&
$
'
c jt . . . . . . 239/344
enib c jt . . . . . . 238/344
enib %
$
Manipulations
Exemple d’utilisation : remove if
algo.h
template <class ForwardIterator, class Predicate>
ForwardIterator
remove if(ForwardIterator first, ForwardIterator last,
Predicate predicate) {
first = find if(first, last, predicate) ;
ForwardIterator next = first ;
return first == last ? first :
remove copy if(++next, last, first, predicate) ;
}
&
$
Manipulations
/* bool odd(int a) { return a % 2 ; } */
int numbers[6] = { 0, 0, 1, 1, 2, 2 } ;
remove if(numbers, numbers + 6, odd) ;
for(int i = 0 ; i < 6 ; i++) cout << numbers[i] << ’ ’ ;
%
&
c jt . . . . . . 240/344
enib %
'
$
Manipulations
STL
partition
'
algo.h
partition (suite)
template <class BidirectionalIterator, class Predicate>
BidirectionalIterator
partition(BidirectionalIterator first,
BidirectionalIterator last, Predicate predicate) {
while(true) {
while(true) {
if(first == last) return first ;
else if(predicate(*first)) ++first ; else break ;
}
à suivre ...
&
'
c jt . . . . . . 241/344
enib Manipulations
$
Manipulations
STL
algo.h
--last ;
while(true) {
if(first == last) return first ;
else if( !predicate(*last)) --last ; else break ;
}
iter swap(first, last) ; ++first ;
}
}
... fin
%
&
$
'
Exemple d’utilisation : partition
c jt . . . . . . 242/344
enib $
Allocations
construct
%
STL
defalloc.h
template <class T1, class T2>
void
construct(T1* p, const T2& value) {
new(p) T1(value) ;
}
/* int less 10(int a) { return a < 10 ? 1 : 0 ; } */
int numbers[6] = { 6, 12, 3, 10, 1, 20 } ;
partition(numbers, numbers + 6, less 10) ;
for(int i = 0 ; i < 6 ; i++) cout << numbers[i] << ’ ’ ;
&
c jt . . . . . . 243/344
enib %
&
c jt . . . . . . 244/344
enib %
'
$
Allocations
'
Exemple d’utilisation : construct
$
Allocations
destroy (1)
STL
defalloc.h
template <class T>
void
destroy(T* pointer) {
pointer->~T() ;
}
&
'
c jt . . . . . . 245/344
enib Allocations
%
&
$
'
Exemple d’utilisation : destroy (1)
c jt . . . . . . 246/344
enib $
Allocations
destroy (2)
%
STL
algobase.h
template <class ForwardIterator>
void
destroy(ForwardIterator first, ForwardIterator last) {
while (first != last) destroy(first++) ;
}
&
c jt . . . . . . 247/344
enib %
&
c jt . . . . . . 248/344
enib %
'
$
Allocations
'
Exemple d’utilisation : destroy (2)
$
Allocations
STL
fill
algo.h
template <class ForwardIterator, class T>
void
fill(ForwardIterator first, ForwardIterator last,
const T& value) {
while (first != last) *first++ = value ;
}
&
'
c jt . . . . . . 249/344
enib Allocations
%
&
$
'
Exemple d’utilisation : fill
c jt . . . . . . 250/344
enib $
Allocations
fill n
%
STL
algobase.h
template <class OutputIterator, class Size, class T>
void
fill n(OutputIterator first, Size n, const T& value) {
while (n-- > 0) *first++ = value ;
}
&
c jt . . . . . . 251/344
enib %
&
c jt . . . . . . 252/344
enib %
'
$
Allocations
'
Exemple d’utilisation : fill n
$
Allocations
uninitialized fill
STL
algobase.h
template <class ForwardIterator, class T>
void
uninitialized fill(ForwardIterator first,
ForwardIterator last, const T& x) {
while (first != last) construct(first++, x) ;
}
&
'
c jt . . . . . . 253/344
enib Allocations
%
&
$
'
Exemple d’utilisation : uninitialized fill
c jt . . . . . . 254/344
enib $
Allocations
uninitialized fill n
%
STL
algobase.h
template <class ForwardIterator, class Size, class T>
void
uninitialized fill n(ForwardIterator first, Size n,
const T& x) {
while (n--) construct(first++, x) ;
}
&
c jt . . . . . . 255/344
enib %
&
c jt . . . . . . 256/344
enib %
'
$
Allocations
'
Exemple d’utilisation : uninitialized fill n
$
Allocations
STL
copy
algobase.h
template <class InputIterator, class OutputIterator>
OutputIterator
copy(InputIterator first, InputIterator last,
OutputIterator result) {
while (first != last) *result++ = *first++ ;
return result ;
}
&
'
c jt . . . . . . 257/344
enib Allocations
%
&
$
'
Exemple d’utilisation : copy
c jt . . . . . . 258/344
enib $
Allocations
copy backward
%
STL
algo.h
template <class BidirectionalIterator1,
class BidirectionalIterator2>
BidirectionalIterator2
copy backward(BidirectionalIterator1 first,
BidirectionalIterator1 last,
BidirectionalIterator2 result) {
while (first != last) *--result = *--last ;
return result ;
}
&
c jt . . . . . . 259/344
enib %
&
c jt . . . . . . 260/344
enib %
'
$
Allocations
'
Exemple d’utilisation : copy backward
$
Allocations
uninitialized copy
STL
algobase.h
template <class InputIterator, class ForwardIterator>
ForwardIterator
uninitialized copy(InputIterator first, InputIterator last,
ForwardIterator result) {
while (first != last) construct(result++, *first++) ;
return result ;
}
&
'
c jt . . . . . . 261/344
enib Allocations
%
&
$
'
Exemple d’utilisation : uninitialized copy
c jt . . . . . . 262/344
enib $
Ensembles
includes (1)
%
STL
algo.h
template <class InputIterator1, class InputIterator2>
bool
includes(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2) {
while(first1 != last1 && first2 != last2)
if(*first2 < *first1) return false ;
else if(*first1 < *first2) ++first1 ;
else (++first1, ++first2) ;
return first2 == last2 ;
}
&
c jt . . . . . . 263/344
enib %
&
c jt . . . . . . 264/344
enib %
'
$
Ensembles
'
Exemple d’utilisation : includes (1)
includes (2)
for(int i = 0 ; i < v1.size() ; i++) v1[i] = i ;
if(includes(v1.begin(), v1.end(), v2.begin(), v2.end()))
cout << "v1 includes v2" << endl ;
else cout << "v1 does not include v2" << endl ;
for(i = 0 ; i < v2.size() ; i++) v2[i] = i + 3 ;
if(includes(v1.begin(), v1.end(), v2.begin(), v2.end()))
cout << "v1 includes v2" << endl ;
else cout << "v1 does not include v2" << endl ;
'
c jt . . . . . . 265/344
enib Ensembles
%
&
$
'
Exemple d’utilisation : includes (2)
%
$
Ensembles
STL
algo.h
template <class InputIterator1, class InputIterator2,
class OutputIterator>
OutputIterator
set union(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result) {
while(first1 != last1 && first2 != last2)
if(*first1 < *first2) *result++ = *first1++ ;
else if(*first2 < *first1) *result++ = *first2++ ;
else { *result++ = *first1++ ; first2++ ; }
return copy(first2, last2, copy(first1, last1, result)) ;
}
char* names[] = { "Alexis", "Dany", "Serge", "Vincent" } ;
vector <char*> v1(4), v2(2) ;
for(int i = 0 ; i < v1.size() ; i++) v1[i] = names[i] ;
v2[0] = "Dany" ; v2[1] = "Vincent" ;
bool inc = includes(v1.begin(), v1.end(), v2.begin(),
v2.end(), compare strings) ;
if(inc) cout << "v1 includes v2" << endl ;
else cout << "v1 does not include v2" << endl ;
c jt . . . . . . 267/344
enib algo.h
c jt . . . . . . 266/344
enib set union (1)
bool compare strings(const char* s1, const char* s2) {
return : :strcmp(s1, s2) < 0 ? 1 : 0 ;
}
&
STL
template <class InputIterator1, class InputIterator2,
class Compare>
bool
includes(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
Compare compare) {
while(first1 != last1 && first2 != last2)
if(compare(*first2, *first1)) return false ;
else if(compare(*first1, *first2)) ++first1 ;
else (++first1, ++first2) ;
return first2 == last2 ;
}
vector<int> v1(10), v2(3) ;
&
$
Ensembles
%
&
c jt . . . . . . 268/344
enib %
'
$
Ensembles
'
Exemple d’utilisation : set union (1)
set union (2)
int v1[3] = { 13, 18, 23 } ;
int v2[4] = { 10, 13, 17, 23 } ;
int result[7] = { 0, 0, 0, 0, 0, 0, 0 } ;
set union(v1, v1 + 3, v2, v2 + 4, result) ;
for(int i = 0 ; i < 7 ; i++) cout << result[i] << ’ ’ ;
cout << endl ;
&
'
c jt . . . . . . 269/344
enib Ensembles
%
&
$
'
Exemple d’utilisation : set union (2)
cout << "word1 : " ;
copy(word1, word1 + : :strlen(word1), iter) ;
cout << "\nword2 : " ;
copy(word2, word2 + : :strlen(word2), iter) ;
set union(word1, word1 + : :strlen(word1), word2,
word2 + : :strlen(word2), iter, less<char>()) ;
cout << endl ;
&
c jt . . . . . . 271/344
enib %
&
STL
algo.h
template <class InputIterator1, class InputIterator2,
class OutputIterator, class Compare>
OutputIterator
set union(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result, Compare compare) {
while(first1 != last1 && first2 != last2)
if(compare(*first1,*first2)) *result++ = *first1++ ;
else if(compare(*first2,*first1))
*result++ = *first2++ ;
else { *result++ = *first1++ ; first2++ ; }
return copy(first2, last2, copy(first1, last1, result)) ;
}
c jt . . . . . . 270/344
enib %
$
Ensembles
set intersection (1)
char* word1 = "ABCDEFGHIJKLMNO" ;
char* word2 = "LMNOPQRSTUVWXYZ" ;
ostream iterator<char> iter(cout, " ") ;
$
Ensembles
STL
algo.h
template <class InputIterator1, class InputIterator2,
class OutputIterator>
OutputIterator
set intersection(
InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result) {
while(first1 != last1 && first2 != last2)
if(*first1 < *first2) ++first1 ;
else if(*first2 < *first1) ++first2 ;
else { *result++ = *first1++ ; ++first2 ; }
return result ;
}
c jt . . . . . . 272/344
enib %
'
$
Ensembles
'
Exemple d’utilisation : set intersection (1)
set intersection (2)
int v1[3] = { 13, 18, 23 } ;
int v2[4] = { 10, 13, 17, 23 } ;
int result[4] = { 0, 0, 0, 0 } ;
set intersection(v1, v1 + 3, v2, v2 + 4, result) ;
for(int i = 0 ; i < 4 ; i++) cout << result[i] << ’ ’ ;
&
'
c jt . . . . . . 273/344
enib Ensembles
%
&
$
'
Exemple d’utilisation : set intersection (2)
set intersection(word1, word1 + : :strlen(word1), word2,
word2 + : :strlen(word2), iter, less<char>()) ;
cout << endl ;
c jt . . . . . . 275/344
enib algo.h
c jt . . . . . . 274/344
enib %
$
Ensembles
STL
algo.h
template <class InputIterator1, class InputIterator2,
class OutputIterator>
OutputIterator
set difference(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result) {
while(first1 != last1 && first2 != last2)
if(*first1 < *first2) *result++ = *first1++ ;
else if(*first2 < *first1) ++first2 ;
else (++first1, ++first2) ;
return copy(first1, last1, result) ;
}
cout << "word1 : " ;
copy(word1, word1 + : :strlen(word1), iter) ;
cout << "\nword2 : " ;
copy(word2, word2 + : :strlen(word2), iter) ;
&
STL
template <class InputIterator1, class InputIterator2,
class OutputIterator, class Compare>
OutputIterator
set intersection(
InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result, Compare compare) {
while(first1 != last1 && first2 != last2)
if(compare(*first1,*first2)) ++first1 ;
else if(compare(*first2,*first1)) ++first2 ;
else { *result++ = *first1++ ; ++first2 ; }
return result ;
}
set difference (1)
char* word1 = "ABCDEFGHIJKLMNO" ;
char* word2 = "LMNOPQRSTUVWXYZ" ;
ostream iterator <char> iter(cout, " ") ;
$
Ensembles
%
&
c jt . . . . . . 276/344
enib %
'
$
Ensembles
'
Exemple d’utilisation : set difference (1)
$
Ensembles
set difference (2)
STL
algo.h
template <class InputIterator1, class InputIterator2,
class OutputIterator, class Compare>
OutputIterator
set difference(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result, Compare compare) {
while(first1 != last1 && first2 != last2)
if(compare(*first1,*first2)) *result++ = *first1++ ;
else if(compare(*first2,*first1)) ++first2 ;
else (++first1, ++first2) ;
return copy(first1, last1, result) ;
}
&
'
c jt . . . . . . 277/344
enib Ensembles
%
&
$
'
Exemple d’utilisation : set difference (2)
c jt . . . . . . 278/344
enib %
$
Recherches
Recherche d’un élément
int array[] = { 1, 3, 5, 6, 8, 12, 14, 15, 17, 20 } ;
int* first = &array[0] ;
int* last = &array[10] ;
int value = (argc > 1) ? atoi(argv[1]) : 14 ;
while(first != last && *first != value) ++first ;
if(first != last) cout << *first << endl ;
&
c jt . . . . . . 279/344
enib %
&
c jt . . . . . . 280/344
enib %
'
$
Recherches
STL
find
'
$
Recherches
Exemple d’utilisation : find
algo.h
template <class InputIterator, class T>
InputIterator
find(InputIterator first, InputIterator last,
const T& value) {
while(first != last && *first != value) ++first ;
return first ;
}
&
'
c jt . . . . . . 281/344
enib Recherches
%
&
$
'
Recherche généralisée d’un élément
c jt . . . . . . 282/344
enib $
Recherches
find if
%
STL
algo.h
template <class InputIterator, class Predicate>
InputIterator
find if(InputIterator first, InputIterator last,
Predicate predicate) {
while(first != last && !predicate(*first)) ++first ;
return first ;
}
/* int even(int n) { return !(n % 2) ; } */
int array[] = { 1, 3, 5, 6, 8, 12, 14, 15, 17, 20 } ;
int* first = &array[0] ;
int* last = &array[10] ;
int (*predicate)(int) = even ;
while(first != last && !predicate(*first)) ++first ;
if(first != last) cout << *first << endl ;
&
c jt . . . . . . 283/344
enib %
&
c jt . . . . . . 284/344
enib %
'
$
Recherches
'
Exemple d’utilisation : find if
$
Recherches
Recherche de 2 éléments adjacents identiques
int array[] = { 1, 3, 5, 6, 8, 12, 12, 15, 17, 20 } ;
int* first = &array[3] ;
int* last = &array[8] ;
int* next = first ;
while(++next != last) {
if(*first == *next) break ;
first = next ;
}
if(next != last) cout << *first << " == " << *next << endl ;
&
'
c jt . . . . . . 285/344
enib Recherches
adjacent find (1)
STL
%
&
$
'
c jt . . . . . . 286/344
enib %
$
Recherches
Exemple d’utilisation : adjacent find (1)
algo.h
template <class InputIterator>
InputIterator
adjacent find(InputIterator first, InputIterator last) {
if(first == last) return last ;
InputIterator next = first ;
while(++next != last) {
if(*first == *next) return first ;
first = next ;
}
return last ;
}
&
c jt . . . . . . 287/344
enib %
&
c jt . . . . . . 288/344
enib %
'
$
Recherches
'
Recherche généralisée de 2 éléments adjacents
/* int equal(int x, int y)
return x == y ;
adjacent find (2)
while(++next != last) {
if(predicate(*first,*next)) break ;
first = next ;
}
'
c jt . . . . . . 289/344
enib Recherches
STL
algo.h
template <class InputIterator, class BinaryPredicate>
InputIterator
adjacent find(InputIterator first, InputIterator last,
BinaryPredicate predicate) {
if(first == last) return last ;
InputIterator next = first ;
while(++next != last) {
if(predicate(*first,*next)) return first ;
first = next ;
}
return last ;
}
*/
int array[] = { 1, 3, 5, 6, 8, 12, 12, 15, 17, 20 } ;
int* first = &array[3] ;
int* last = &array[8] ;
int* next = first ;
int (*predicate)(int,int) = equal ;
&
$
Recherches
%
&
$
'
Exemple d’utilisation : adjacent find (2)
c jt . . . . . . 290/344
enib %
$
Recherches
Recherche d’une séquence
int array1[] = { 1, 3, 6, 6, 8, 12, 12, 15, 17, 6 } ;
int array2[] = { 6, 8, 12, 12, 15, 17, 6, 1, 3, 6 } ;
int* first1 = &array1[2] ;
int* last1 = &array1[10] ;
int* first2 = &array2[3] ;
int* last2 = &array2[7] ;
ptrdiff t d1 = last1 - first1 ;
ptrdiff t d2 = last2 - first2 ;
int* result = last1 ;
&
c jt . . . . . . 291/344
enib %
&
c jt . . . . . . 292/344
enib %
'
$
Recherches
'
Recherche d’une séquence (suite)
'
c jt . . . . . . 293/344
enib Recherches
search (1 - suite)
&
STL
STL
search (1)
à suivre ...
%
&
$
'
c jt . . . . . . 295/344
enib c jt . . . . . . 294/344
enib %
$
Recherches
Exemple d’utilisation : search (1)
algo.h
if(d1 >= d2) {
ForwardIterator1 current1 = first1 ;
ForwardIterator2 current2 = first2 ;
while(current2 != last2) {
if(*current1++ != *current2++) {
if(d1-- == d2) result = last1 ;
else { current1 = ++first1 ; current2 = first2 ; }
}
}
result = (current2 == last2) ? first1 : last1 ;
}
return result ;
}
... fin
algo.h
template <class ForwardIterator1, class ForwardIterator2>
ForwardIterator1
search(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2) {
ptrdiff t d1 = last1 - first1 ;
ptrdiff t d2 = last2 - first2 ;
ForwardIterator1 result = last1 ;
if(d1 >= d2) {
int* current1 = first1 ;
int* current2 = first2 ;
while(current2 != last2) {
if(*current1++ != *current2++) {
if(d1-- == d2) result = last1 ;
else { current1 = ++first1 ; current2 = first2 ; }
}
}
result = (current2 == last2) ? first1 : last1 ;
}
&
$
Recherches
%
&
c jt . . . . . . 296/344
enib %
'
$
Recherches
'
Recherche généralisée d’une séquence
Recherche généralisée d’une séquence (suite)
/* int equal(int x, int y) { return x == y ; } */
if(d1 >= d2) {
int* current1 = first1 ;
int* current2 = first2 ;
while(current2 != last2) {
if( !predicate(*current1++,*current2++)) {
if(d1-- == d2) result = last1 ;
else { current1 = ++first1 ; current2 = first2 ; }
}
}
result = (current2 == last2) ? first1 : last1 ;
}
int array1[] = { 1, 3, 6, 6, 8, 12, 12, 15, 17, 6 } ;
int array2[] = { 6, 8, 12, 12, 15, 17, 6, 1, 3, 6 } ;
int* first1 = &array1[2] ;
int* last1 = &array1[10] ;
int* first2 = &array2[3] ;
int* last2 = &array2[7] ;
ptrdiff t d1 = last1 - first1 ;
ptrdiff t d2 = last2 - first2 ;
int* result = last1 ;
&
'
int (*predicate)(int,int) = equal ;
c jt . . . . . . 297/344
enib Recherches
search (2)
STL
%
&
$
'
algo.h
à suivre ...
c jt . . . . . . 299/344
enib c jt . . . . . . 298/344
enib %
&
%
$
Recherches
search (2 -suite)
template <class ForwardIterator1, class ForwardIterator2,
class BinaryPredicate>
ForwardIterator1
search(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
BinaryPredicate predicate) {
ptrdiff t d1 = last1 - first1 ;
ptrdiff t d2 = last2 - first2 ;
ForwardIterator1 result = last1 ;
&
$
Recherches
STL
algo.h
if(d1 >= d2) {
ForwardIterator1 current1 = first1 ;
ForwardIterator2 current2 = first2 ;
while(current2 != last2) {
if( !predicate(*current1++,*current2++)) {
if(d1-- == d2) result = last1 ;
else { current1 = ++first1 ; current2 = first2 ; }
}
}
result = (current2 == last2) ? first1 : last1 ;
}
return result ;
}
... fin
c jt . . . . . . 300/344
enib %
'
$
Recherches
'
$
Recherches
Exemple d’utilisation : search (2)
Occurences d’un élément
int array[] = { 1, 3, 6, 6, 8, 12, 12, 15, 17, 6 } ;
int* first = &array[0] ;
int* last = &array[10] ;
int n0 = 2, n = n0 ;
int value = (argc > 1) ? atoi(argv[1]) : 6 ;
while(first != last) if(*first++ == value) ++n ;
if(first == last) cout << (n - n0) << endl ;
&
c jt . . . . . . 301/344
enib '
Recherches
count
STL
%
&
$
'
c jt . . . . . . 302/344
enib %
$
Recherches
Exemple d’utilisation : count
algo.h
template <class InputIterator, class T, class Size>
void
count(InputIterator first, InputIterator last,
const T& value, Size& n) {
while(first != last) {
if(*first++ == value) ++n ;
}
}
&
c jt . . . . . . 303/344
enib %
&
c jt . . . . . . 304/344
enib %
'
$
Recherches
'
Occurences conditionnelles
/* int even(int n)
return !(n % 2) ;
$
Recherches
count if
STL
algo.h
template <class InputIterator, class Predicate, class Size>
void
count if(InputIterator first, InputIterator last,
Predicate predicate, Size& n) {
while(first != last) {
if(predicate(*first++)) ++n ;
}
}
*/
int array[] = { 1, 3, 6, 6, 8, 12, 12, 15, 17, 6 } ;
int* first = &array[0] ;
int* last = &array[10] ;
int n0 = 2, n = n0 ;
int (*predicate)(int) = even ;
while(first != last) if(predicate(*first++)) ++n ;
if(first == last) cout << (n - n0) << endl ;
&
'
c jt . . . . . . 305/344
enib Recherches
%
&
$
'
Exemple d’utilisation : count if
&
c jt . . . . . . 307/344
enib c jt . . . . . . 306/344
enib %
$
Recherches
Recherche dichotomique
%
&
c jt . . . . . . 308/344
enib %
'
$
Recherches
binary search (1)
STL
'
binary search (1 - suite)
algo.h
$
Recherches
template <class RandomAccessIterator, class T>
bool
binary search(RandomAccessIterator first,
RandomAccessIterator last, const T& value) {
ptrdiff t length = last - first ;
ptrdiff t half = length / 2 ;
RandomAccessIterator middle ;
STL
algo.h
while(length > 0) {
half = length / 2 ; middle = first + half ;
if(*middle < value) {
first = middle + 1 ;
length = length - half - 1 ;
}
else length = half ;
}
return first != last && !(value < *first) ;
à suivre ...
}
... fin
&
'
c jt . . . . . . 309/344
enib Recherches
%
&
$
'
Exemple d’utilisation : binary search (1)
&
c jt . . . . . . 311/344
enib c jt . . . . . . 310/344
enib %
$
Recherches
Recherche dichotomique généralisée
%
&
c jt . . . . . . 312/344
enib %
'
$
Recherches
binary search (2)
STL
'
binary search (2 - suite)
algo.h
$
Recherches
template <class RandomAccessIterator, class T,
class Compare>
bool
binary search(RandomAccessIterator first,
RandomAccessIterator last,
const T& value, Compare compare) {
ptrdiff t length = last - first ;
ptrdiff t half = length / 2 ;
RandomAccessIterator middle ;
STL
algo.h
while(length > 0) {
half = length / 2 ; middle = first + half ;
if(compare(*middle,value)) {
first = middle + 1 ;
length = length - half - 1 ;
}
else length = half ;
}
return first != last && !compare(value,*first) ;
}
à suivre ...
&
'
c jt . . . . . . 313/344
enib Recherches
... fin
%
&
$
'
c jt . . . . . . 314/344
enib $
Standard Template Library
Exemple d’utilisation : binary search (2)
%
Index
Index
1. Liste des fichiers STL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
2. Index thématique des classes . . . . . . . . . . . . . . . . . . . . . . . . . . 318
3. Index thématique des fonctions . . . . . . . . . . . . . . . . . . . . . . . 323
4. Index alphabétique des classes . . . . . . . . . . . . . . . . . . . . . . . . 332
5. Index alphabétique des fonctions . . . . . . . . . . . . . . . . . . . . . . 336
&
c jt . . . . . . 315/344
enib %
&
c jt . . . . . . 316/344
enib %
'
$
Standard Template Library
'
Index thématique des classes
Liste des fichiers STL
algo.h
algobase.h
bool.h
bvector.h
defalloc.h
deque.h
function.h
iterator.h
map.h
'
Index thématique des classes
multimap.h
multiset.h
pair.h
projectn.h
set.h
stack.h
tempbuf.h
tree.h
vector.h
&
1. Itérateurs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
2. Conteneurs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
3. Fonctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
c jt . . . . . . 317/344
enib Standard Template Library
%
&
$
'
Index thématique des classes
&
$
Standard Template Library
Itérateurs
back insert iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
bidirectional iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17, 29
forward iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17, 25
front insert iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
input iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17, 21
insert iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
istream iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
ostream iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
output iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17, 18
random access iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17, 34
reverse bidirectional iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
reverse iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
c jt . . . . . . 319/344
enib c jt . . . . . . 318/344
enib %
$
Standard Template Library
Index thématique des classes
%
&
Conteneurs
deque . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 — 79
list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 — 88
map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 — 124
multimap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 — 133
multiset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 — 115
pair . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 — 97
priority queue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 — 144
queue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 — 141
rb tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 — 96
set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 — 107
stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 — 138
vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 — 72
c jt . . . . . . 320/344
enib %
'
$
Standard Template Library
'
Index thématique des classes
&
'
Classes de fonctions
binary compose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
binary function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
divides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
equal to . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
greater . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
greater equal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ident . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
less . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
less equal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
logical and . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
logical or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
logical not . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
c jt . . . . . . 321/344
enib Standard Template Library
Index thématique des classes
63
44
46
49
50
50
52
51
51
53
53
54
Classes de fonctions
minus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
modulus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
negate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
not equal to . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
plus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
pointer to unary function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
pointer to binary function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
select1st . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
unary compose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
unary function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
%
&
$
'
Index thématique des fonctions
%
$
Standard Template Library
Calculs
accumulate (1) ......................................
accumulate (2) ......................................
adjacent difference (1) .............................
adjacent difference (2) .............................
inner product (1) ...................................
inner product (2) ...................................
partial sum (1) ......................................
partial sum (2) ......................................
1. Calculs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
2. Comparaisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
3. Manipulations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
4. Allocations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
5. Ensembles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
6. Recherches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
c jt . . . . . . 323/344
enib c jt . . . . . . 322/344
enib 45
47
47
49
45
56
58
52
46
60
44
Index thématique des fonctions
Index thématique des fonctions
&
$
Standard Template Library
%
&
147
150
165
168
153
156
159
162
c jt . . . . . . 324/344
enib %
'
$
Standard Template Library
'
Index thématique des fonctions
Index thématique des fonctions
Comparaisons
Comparaisons (suite)
equal (1) ............................................
equal (2) ............................................
lexicographical compare (1) ........................
lexicographical compare (2) ........................
max (1) ..............................................
max (2) ..............................................
max element (1) ......................................
max element (2) ......................................
min (1) ..............................................
&
'
195
198
201
204
173
173
176
178
181
c jt . . . . . . 325/344
enib Standard Template Library
min (2) ..............................................
min element (1) ......................................
min element (2) ......................................
mismatch (1) .........................................
mismatch (2) .........................................
operator> ............................................
operator<= ...........................................
operator>= ...........................................
operator != ...........................................
%
&
$
'
Index thématique des fonctions
181
184
186
189
192
170
170
170
170
c jt . . . . . . 326/344
enib %
$
Standard Template Library
Index thématique des fonctions
Manipulations
Manipulations (suite)
for each ..............................................
generate .............................................
generate n ...........................................
iter swap ............................................
partition ............................................
remove ................................................
remove copy ..........................................
remove copy if .......................................
remove if ............................................
&
$
Standard Template Library
replace ..............................................
replace copy .........................................
replace copy if ......................................
replace if ...........................................
swap ..................................................
swap ranges ..........................................
transform (1) ........................................
transform (2) ........................................
214
216
219
209
241
237
233
235
239
c jt . . . . . . 327/344
enib %
&
225
229
231
227
207
211
221
223
c jt . . . . . . 328/344
enib %
'
$
Standard Template Library
'
Index thématique des fonctions
Index thématique des fonctions
Allocations
&
'
Ensembles
c jt . . . . . . 329/344
enib Standard Template Library
%
&
$
'
Index thématique des fonctions
c jt . . . . . . 330/344
enib %
$
Standard Template Library
Index alphabétique des classes
back insert iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
bidirectional iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17, 29
binary compose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
binary function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
deque . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 — 79
divides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
equal to . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
forward iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17, 25
front insert iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
greater . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
greater equal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Recherches
&
$
Standard Template Library
c jt . . . . . . 331/344
enib %
&
c jt . . . . . . 332/344
enib %
'
'
Index alphabétique des classes
ident . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
input iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17, 21
insert iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
istream iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
less . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
less equal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 — 88
logical and . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
logical or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
logical not . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 — 124
minus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
modulus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
multimap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 — 133
multiset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 — 115
negate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
not equal to . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
ostream iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
output iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17, 18
pair . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 — 97
plus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
pointer to unary function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
pointer to binary function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
priority queue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 — 144
c jt . . . . . . 333/344
enib Standard Template Library
%
&
$
'
Index alphabétique des classes
c jt . . . . . . 335/344
enib c jt . . . . . . 334/344
enib %
$
Standard Template Library
Index alphabétique des fonctions
queue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 — 141
random access iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17, 34
rb tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 — 96
reverse bidirectional iterator . . . . . . . . . . . . . . . . . . . . . . . . . . 37
reverse iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
select1st . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 — 107
stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 — 138
times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
unary compose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
unary function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 — 72
&
$
Standard Template Library
Index alphabétique des classes
&
'
$
Standard Template Library
accumulate (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
accumulate (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
adjacent difference (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
adjacent difference (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
adjacent find (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
adjacent find (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
binary search (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
binary search (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
copy backward . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
%
&
147
150
165
168
287
290
309
313
244
258
260
303
c jt . . . . . . 336/344
enib %
'
$
Standard Template Library
'
Index alphabétique des fonctions
count if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
destroy (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
destroy (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
equal (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
equal (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
fill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
fill n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
find . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
find if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
for each . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
generate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
generate n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
&
'
Index alphabétique des fonctions
306
246
248
195
198
250
252
281
284
214
216
219
c jt . . . . . . 337/344
enib Standard Template Library
includes (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
includes (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
inner product (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
inner product (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
iter swap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
lexicographical compare (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
lexicographical compare (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
max (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
max (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
max element (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
max element (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
min (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
%
&
$
'
Index alphabétique des fonctions
min (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
min element (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
min element (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
mismatch (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
mismatch (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
operator> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
operator<= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
operator>= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
operator != . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
partial sum (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
partial sum (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
remove . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
&
$
Standard Template Library
264
266
153
156
209
201
204
173
173
176
178
181
c jt . . . . . . 338/344
enib %
$
Standard Template Library
Index alphabétique des fonctions
remove copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
remove copy if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
remove if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
search (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
search (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
set difference (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
set difference (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
set intersection (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
set intersection (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
set union (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
set union (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
swap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
181
184
186
189
192
170
170
170
170
159
162
237
c jt . . . . . . 339/344
enib %
&
233
235
239
294
299
276
278
272
274
268
270
207
c jt . . . . . . 340/344
enib %
'
$
Standard Template Library
'
Index alphabétique des fonctions
swap ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
transform (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
transform (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
uninitialized copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
uninitialized fill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
uninitialized fill n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
&
'
$
Standard Template Library
Références
211
221
223
262
254
256
c jt . . . . . . 341/344
enib Références STL
Références
1. Bibliographie . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
2. Sites Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
%
&
$
'
Bibliographie
c jt . . . . . . 342/344
enib %
$
Références STL
Sites Internet
Musser D.R., Saini A., STL tutorial and reference guide :
C++ programming with the Standard Template Library,
Addison–Wesley — 1996
ftp ://research.att.com/dist/c++std/WP/
Stepanov A., Lee M., The Standard Template Library,
Hewlett–Packard — 1995
http ://www.ualberta.ca/~nyu/stl/stl.html
http ://weber.u.washington.edu/~bytewave/bytewave stl.html
http ://www.aw.com/cp/musser-saini.html
&
c jt . . . . . . 343/344
enib %
&
c jt . . . . . . 344/344
enib %