Is there a nice way to assign std::minmax(a, b) to std::tie(a, b)?

You can use an initializer list for minmax: std::tie(a, b) = std::minmax({a, b}); This causes temporary objects to be created, just like when using unary plus, but has the benefit that it works with types lacking the unary plus operator too. using namespace std::string_view_literals; auto [a, b] = std::make_pair(“foo”sv, “bar”sv); std::tie(a, b) = std::minmax({a, b}); … Read more

Why did the range based ‘for’ loop specification change in C++17? [duplicate]

Using auto __begin = begin_expr, __end = end_expr; requires both begin_expr and end_expr to return the same type. This means you cannot have a sentinel iterator type that is different from the beginning type. Using auto __begin = begin_expr ; auto __end = end_expr ; fixes that issue while proving full backwards compatibility with C++14.

Changed rules for protected constructors in C++17?

The definition of aggregate changed since C++17. Before C++17 no base classes Since C++17 no virtual, private, or protected (since C++17) base classes That means, for B and D, they’re not aggregate type before C++17, then for B{} and D{}, value-initialization will be performed, then the defaulted default constructor will be called; which is fine, … Read more

Equivalent ternary operator for constexpr if?

No, there is no constexepr conditional operator. But you could wrap the whole thing in a lambda and immediately evaluate it (an IIFE): template<typename Mode> class BusAddress { public: explicit constexpr BusAddress(Address device) : mAddress([&]{ if constexpr (Mode::write) { return device.mDevice << 1; } else { return (device.mDevice << 1) | 0x01; } }()) { … Read more

Difference between execution policies and when to use them

What is the difference between seq and par/par_unseq? std::for_each(std::execution::seq, std::begin(v), std::end(v), function_call); std::execution::seq stands for sequential execution. It is the default if you do not specify the execution policy at all. It will force the implementation to execute all function calls in sequence. It is also guaranteed that everything is executed by the calling thread. … Read more

Exact moment of “return” in a C++-function

Due to Return Value Optimization (RVO), a destructor for std::string res in make_string_ok may not be called. The string object can be constructed on the caller’s side and the function may only initialize the value. The code will be equivalent to: void make_string_ok(std::string& res){ Writer w(res); } int main() { std::string res(“A”); make_string_ok(res); } That … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)