Xavier Lamorlette
Cette page est ancienne : elle contient des notes sur les nouveautés de C++ 11, pertinentes lors du passage de C++ 03 à C++11.
Sommaire :
std::array
std::vector v = {0, 1, 2, 3, 4, 5};
for (const int & i: v) // access by const reference
for (auto i: v) // access by value: i is an int
for (auto & i: v) // access by reference: i is an int &
for (const auto & i: v) // access by const reference: i is a const int &
for (int n: {0, 1, 2, 3, 4, 5}) // the initialiser may be a braced-init-list
map address_book;
for (auto address_entry: address_book) {
cout << address_entry.first << " < " << address_entry.second << ">" << endl;
}
class A {
int a[10] = {1, 2}; // non-static data member with initialiser
};
Delegating constructor
class M {
int x;
public:
M(int v):
x(v) {
}
M():
M(0) {
}
};
std::array
std::array
= C array
unordered_map<K, T>
unordered_multimap<K, T>
unordered_set<K>
unordered_multiset<K>
boost::variant
(C++17: std::variant
): discriminated union of fixed and finite set of typesboost::any
: sort of unbounded union; store a value of an arbitrary typeboost::optional
boost::optional
and std::experimental::optional
are differentnullopt
: no value*
)#include <algorithm>
// are all of the elements positive?
all_of(first, first+n, ispositive());
// is there at least one positive element?
any_of(first, first+n, ispositive());
// are none of the elements positive?
none_of(first, first+n, ispositive());
La dernière mise à jour de cette page date d'août 2020.
Le contenu de ce site est, en tant qu'œuvre originale de l'esprit, protégé par le droit d'auteur.
Pour tout commentaire, vous pouvez m'écrire à xavier.lamorlette@gmail.com.