diff options
author | Ole-Morten Duesund <olemd@odinprosjekt.no> | 2020-12-07 15:47:28 +0100 |
---|---|---|
committer | Ole-Morten Duesund <olemd@odinprosjekt.no> | 2020-12-17 09:57:53 +0100 |
commit | 8183086513ae439220ae1facb1e93fc23b9a116b (patch) | |
tree | 6b81af4c33b247cacd0ac9e4a83478271e7d968a /src/corelib/doc/snippets/code | |
parent | 970e54c63d487ff5a334b8037ce0890fceb24e0f (diff) |
Add sections about std containers and algorithms
Add section comparing Qt containers and std containers.
Add snippets showing use of std algorithms with Qt containers.
Task-number: QTBUG-86584
Pick-to: 6.0
Change-Id: I1133a5214a5acd086c37658ca11ab205a19a489b
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'src/corelib/doc/snippets/code')
-rw-r--r-- | src/corelib/doc/snippets/code/doc_src_containers.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/corelib/doc/snippets/code/doc_src_containers.cpp b/src/corelib/doc/snippets/code/doc_src_containers.cpp index e5ccf0bb48..834056174f 100644 --- a/src/corelib/doc/snippets/code/doc_src_containers.cpp +++ b/src/corelib/doc/snippets/code/doc_src_containers.cpp @@ -319,3 +319,24 @@ QSet<int> set(list.begin(), list.end()); Will generate a QSet containing 1, 2, 3, 4, 5. */ //! [25] + +//! [26] +QList<int> list { 2, 3, 1 }; + +std::sort(list.begin(), list.end()); +/* + Sort the list, now contains { 1, 2, 3 } +*/ + +std::reverse(list.begin(), list.end()); +/* + Reverse the list, now contains { 3, 2, 1 } +*/ + +int even_elements = + std::count_if(list.begin(), list.end(), [](int element) { return (element % 2 == 0); }); +/* + Count how many elements that are even numbers, 1 +*/ + +//! [26] |