Workarounds for no ‘rvalue references to *this’ feature

Good question. I attempted writing a similar sort of proxy class recently but never achieved a good solution. The best I found was calling a member function on every use where the proxy was required to be an r-value: ORef<T> move() { return ORef<T>( this->release() ); } This changes the semantics of declaring something an … Read more

Initialization of a constant reference with a number [duplicate]

A non-const reference cannot point to a literal. You cannot bind a literal to a reference to non-const (because modifying the value of a literal is not an operation that makes sense) and only l-values can be bound to references to non-const. You can however bind a literal to a reference to const. The “const” … Read more

Why do some people use swap for move assignments?

It’s my fault. (half-kidding, half-not). When I first showed example implementations of move assignment operators, I just used swap. Then some smart guy (I can’t remember who) pointed out to me that the side effects of destructing the lhs prior to the assignment might be important (such as the unlock() in your example). So I … Read more

Is there any case where a return of a RValue Reference (&&) is useful?

There are a few occasions when it is appropriate, but they are relatively rare. The case comes up in one example when you want to allow the client to move from a data member. For example: template <class Iter> class move_iterator { private: Iter i_; public: … value_type&& operator*() const {return std::move(*i_);} … };

C++11 make_pair with specified template parameters doesn’t compile

This is not how std::make_pair is intended to be used; you are not supposed to explicitly specify the template arguments. The C++11 std::make_pair takes two arguments, of type T&& and U&&, where T and U are template type parameters. Effectively, it looks like this (ignoring the return type): template <typename T, typename U> [return type] … Read more

What are the main purposes of std::forward and which problems does it solve?

You have to understand the forwarding problem. You can read the entire problem in detail, but I’ll summarize. Basically, given the expression E(a, b, … , c), we want the expression f(a, b, … , c) to be equivalent. In C++03, this is impossible. There are many attempts, but they all fail in some regard. … Read more

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