Is there a standard way of moving a range into a vector?

You use a move_iterator with insert: v1.insert(v1.end(), make_move_iterator(v2.begin()), make_move_iterator(v2.end())); The example in 24.5.3 is almost exactly this. You’ll get the optimization you want if (a) vector::insert uses iterator-tag dispatch to detect the random-access iterator and precalculate the size (which you’ve assumed it does in your example that copies), and (b) move_iterator preserves the iterator category … Read more

enum vs constexpr for actual static constants inside classes

For the record, the static constexpr version will work like you’d expected in C++17. From N4618 Annex D.1 [depr.static_constexpr]: D.1 Redeclaration of static constexpr data members [depr.static_constexpr] For compatibility with prior C++ International Standards, a constexpr static data member may be redundantly redeclared outside the class with no initializer. This usage is deprecated. [Example: struct … Read more

How to get duration, as int milli’s and float seconds from ?

Is this what you’re looking for? #include <chrono> #include <iostream> int main() { typedef std::chrono::high_resolution_clock Time; typedef std::chrono::milliseconds ms; typedef std::chrono::duration<float> fsec; auto t0 = Time::now(); auto t1 = Time::now(); fsec fs = t1 – t0; ms d = std::chrono::duration_cast<ms>(fs); std::cout << fs.count() << “s\n”; std::cout << d.count() << “ms\n”; } which for me prints … Read more

Boost asio thread_pool join does not wait for tasks to be finished

The best practice is not to reuse the pool (what would be the use of pooling, if you keep creating new pools?). If you want to be sure you “time” the batches together, I’d suggest using when_all on futures: Live On Coliru #define BOOST_THREAD_PROVIDES_FUTURE_WHEN_ALL_WHEN_ANY #include <iostream> #include <boost/bind.hpp> #include <boost/asio.hpp> #include <boost/thread.hpp> uint64_t foo(uint64_t begin) … Read more