C++ Library Extensions 2022.12.09
To help learn modern C++ programming
030-why_vector.cpp
Go to the documentation of this file.
1#include <tpf_output.hpp>
3
5{
7
8 size_t count = 100;
9 using element_t = int;
10
11 auto generator =
12 tpf::chrono_random::random_generator<element_t>(0, 1'000);
13
15
16 stream << "Initializing vector with " << count << " elements." << tpf::endl;
17 std::vector<int> v; v.reserve(count);
18
19 for(size_t i=0; i < count; ++i)
20 v.emplace_back(generator());
21
22 std::sort(v.begin(), v.end());
23 stream << "Elapsed: " << sw.elapsed_time() << tpf::endl;
24
25 stream << "Initializing list with " << count << " elements." << tpf::endl;
26 std::list<int> l;
27 for(size_t i=0; i < count; ++i)
28 {
29 l.insert(l.end(), generator());
30 }
31
32 l.sort();
33 stream << "Elapsed: " << sw.elapsed_time() << tpf::endl;
34
35 stream << "v = " << v << tpf::endl;
36 stream << "l = " << l << tpf::endl;
37
38}
39
40int main()
41{
43}
std::atomic< int > count
Definition: 022-mutex.cpp:10
void random_initialization_test()
int main()
tpf::sstream stream
std::string elapsed_time(bool bReset=true, TimeUnit dummy_time=TimeUnit{}) const
ContainerType< EleType > sort(ContainerType< EleType, Types... > container, sort_order order=sort_order::ascending, sort_method method=sort_method::size)
Definition: tpf_set.hpp:438
constexpr auto endl
Definition: tpf_output.hpp:973
Stream output operators << are implemented.