Why are by-value parameters excluded from NRVO?

Here’s why copy elision doesn’t make sense for parameters. It’s really about the implementation of the concept at the compiler level. Copy elision works by essentially constructing the return value in-place. The value isn’t copied out; it’s created directly in its intended destination. It’s the caller who provides the space for the intended output, and … Read more

Lambda passed by reference runs when invoked in the constructor, but not when later stored in a data member

You’re not storing a lambda, you’re storing a reference to a std::function. In fact, that std::function is being created as a temporary when the lambda is implicitly converted to std::function. That std::function temporary dies after the line where the constructor is invoked. LambdaStore(const std::function<void(float)>& _fn) // _fn refers to a temporary : fn(_fn) { fn(11.1f); … Read more

Is there a reason declval returns add_rvalue_reference instead of add_lvalue_reference

With add_rvalue_reference: declval<Foo>() is of type Foo&&. declval<Foo&>() is of type Foo& (reference collapsing: “Foo& &&” collapses to Foo&). declval<Foo&&>() is of type Foo&& (reference collapsing: “Foo&& &&” collapses to Foo&&). With add_lvalue_reference: declval<Foo>() would be of type Foo&. declval<Foo&>() would be of type Foo& (reference collapsing: “Foo& &” collapses to Foo&). declval<Foo&&>() would be … Read more

Do I have to use atomic for “exit” bool variable?

Do I have to use atomic for “exit” bool variable? Yes. Either use atomic<bool>, or use manual synchronization through (for instance) an std::mutex. Your program currently contains a data race, with one thread potentially reading a variable while another thread is writing it. This is Undefined Behavior. Per Paragraph 1.10/21 of the C++11 Standard: The … Read more

How can you efficiently check whether two std::weak_ptr pointers are pointing to the same object?

Completely rewriting this answer because I totally misunderstood. This is a tricky thing to get right! The usual implementation of std::weak_ptr and std::shared_ptr that is consistent with the standard is to have two heap objects: the managed object, and a control block. Each shared pointer that refers to the same object contains a pointer to … Read more

When does lvalue-to-rvalue conversion happen, how does it work, and can it fail?

I think the lvalue-to-rvalue conversion is more than just use an lvalue where an rvalue is required. It can create a copy of a class, and always yields a value, not an object. I’m using n3485 for “C++11” and n1256 for “C99”. Objects and values The most concise description is in C99/3.14: object region of … Read more

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