Category : initializer-list

So, this isn’t really something I have to do, I was just playing around. I wrote a Vector class for vectors of any numeric type and any number of coordinates. It is used as Vector<NumericType, [num of coords]>. Here is the code: #include <array> #include <functional> namespace World { template <typename NumType, unsigned char Size> ..

Read more

I understand unique_ptr can only be move constructed and move assigned, but the following code still puzzles me, #include <map> #include <memory> #include <utility> using namespace std; int main() { map<int, unique_ptr<int>> a{}; // 1, OK map<int, map<int, unique_ptr<int>>> b{{1, {}}}; // 2, error, copy ctor accessed map<int, map<int, unique_ptr<int>>> d; // 3, workaround d.try_emplace(1, ..

Read more

I am trying to expand this answer to return the result of the function in addition to the CPU time. Here is my code: #include <chrono> #include <iostream> #include <utility> template <typename F, typename… Args> auto MeasureFunctionCpuTime(F func, Args&&… args) { using TimeVar = std::chrono::high_resolution_clock::time_point; constexpr auto get_now = std::chrono::high_resolution_clock::now; TimeVar t1 = get_now(); const ..

Read more

Suppose I have 3 concepts: ostreamable istreamable iostreamable Where the definitions: template <typename T> concept ostreamable = requires (std::ostream& os, T arg) { {os << arg} -> std::convertible_to<std::ostream&>; }; template <typename T> concept istreamable = requires (std::istream& is, T& arg) { {is >> arg} -> std::convertible_to<std::istream&>; }; template <typename T> concept iostreamable = ostreamable<T> && ..

Read more