Why use std::make_unique in C++17?

You’re right that the main reason was removed. There are still the don’t use new guidelines and that it is less typing reasons (don’t have to repeat the type or use the word new). Admittedly those aren’t strong arguments but I really like not seeing new in my code. Also don’t forget about consistency. You … Read more

How does guaranteed copy elision work?

Copy elision was permitted to happen under a number of circumstances. However, even if it was permitted, the code still had to be able to work as if the copy were not elided. Namely, there had to be an accessible copy and/or move constructor. Guaranteed copy elision redefines a number of C++ concepts, such that … Read more

std::ignore with structured bindings?

The structured bindings proposal contains a dedicated section answering your question (P0144R2): 3.8 Should there be a way to explicitly ignore components? The motivation would be to silence compiler warnings about unused names. We think the answer should be “not yet.” This is not motivated by use cases (silencing compiler warnings is a motivation, but … Read more

Why is there no support for concatenating std::string and std::string_view?

The reason for this is given in n3512 string_ref: a non-owning reference to a string, revision 2 by Jeffrey Yasskin: I also omitted operator+(basic_string, basic_string_ref) because LLVM returns a lightweight object from this overload and only performs the concatenation lazily. If we define this overload, we’ll have a hard time introducing that lightweight concatenation later. … Read more

experimental::filesystem linker error

The Filesystem TS is nothing to do with C++1z support, it is a completely separate specification not part of the C++1z working draft. GCC’s implementation (in GCC 5.3 and later) is even available in C++11 mode. You just need to link with -lstdc++fs to use it. (The relevant library, libstdc++fs.a, is a static library, so … Read more

Lambda implicit capture fails with variable declared from structured binding

Core issue 2313 changed the standard so that structured bindings are never names of variables, making them never capturable. P0588R1’s reformulation of lambda capture wording makes this prohibition explicit: If a lambda-expression […] captures a structured binding (explicitly or implicitly), the program is ill-formed. Note that this wording is supposedly a placeholder while the committee … Read more

Most elegant way to write a one-shot ‘if’

Use std::exchange: if (static bool do_once = true; std::exchange(do_once, false)) You can make it shorter reversing the truth value: if (static bool do_once; !std::exchange(do_once, true)) But if you are using this a lot, don’t be fancy and create a wrapper instead: struct Once { bool b = true; explicit operator bool() { return std::exchange(b, false); … Read more

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