Why use a perfectly forwarded value (a functor)?

In Brief… The TL;DR, you want to preserve the value category (r-value/l-value nature) of the functor because this can affect the overload resolution, in particular the ref-qualified members. Function definition reduction To focus on the issue of the function being forwarded, I’ve reduced the sample (and made it compile with a C++11 compiler) to; template<class … Read more

Proper way (move semantics) to return a std::vector from function calling in C++11

If you’re using a C++0x-compatible compiler and standard library, you get better performance from the first example without doing anything. The return value of get_vector(_n, _m) is a temporary, and the move constructor for std::vector (a constructor taking an rvalue reference) will automatically be called with no further work on your part. In general, non-library … Read more

Template specialization with empty brackets and struct

There are different levels of template specialization: 1) Template declaration (no specialization) template <class Key, class Value> struct Foo {}; 2) Partial specialization template <class Key> struct Foo<Key, int> {}; 3) Full/explicit specialization template <> struct Foo<std::string, int> {}; Then, when instantiating the templates, the compiler will choose the most specialized definition available: Foo<std::string, std::string> … Read more

Vary range of uniform_int_distribution

Distribution objects are lightweight. Simply construct a new distribution when you need a random number. I use this approach in a game engine, and, after benchmarking, it’s comparable to using good old rand(). Also, I’ve asked how to vary the range of distribution on GoingNative 2013 live stream, and Stephen T. Lavavej, a member of … Read more

Noexcept and copy, move constructors

This is a multi-faceted question, so bear with me while I go through the various aspects. The standard library expects all user types to always give the basic exception guarantee. This guarantee says that when an exception is thrown, the involved objects are still in a valid, if unknown, state, that no resources are leaked, … Read more

How to change mode from c++98 mode in Dev-C++ to a mode that supports C++0x (range based for)?

Go to Tools -> Compiler Options -> “Compiler” tab Check the checkbox labeled, “Add the following commands when calling the compiler” And add in the text entry box, “-std=c++11” or if that doesn’t work “-std=C++0x“ Should be something like that anyway, I haven’t had Dev C++ installed for many years, so I had to look … Read more

Is this change in overload resolution between Clang 3.5 and 3.6 correct or a bug?

I believe Clang is correct to produce this error: The [temp.inst] section of the C++ standard in paragraph 10 says: If a function template or a member function template specialization is used in a way that involves overload resolution, a declaration of the specialization is implicitly instantiated (14.8.3). Forming the implicit conversion sequence necessary to … Read more

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