Why does adding const turn a forwarding reference into an rvalue reference?

The official name is not universal reference, but forwarding reference. The Standard states that only rvalue references to cv-unqualified template parameters fall in this category: 14.8.2.1 Deducing template arguments from a function call [temp.deduct.call] 3 If P is a cv-qualified type, the top level cv-qualifiers of P’s type are ignored for type deduction. If P … Read more

C++11: Why is private member template accessible outside class?

This is definitely a compiler bug, and actually one that has been known for quite some time: GCC #47346 (first reported in Jan 2011) and Clang #15914 (first reported May 2013). Your __tklass is clearly private, and the template alias is not marked friend, so this should be a simple access error. The simplest reproduction … Read more

Pointer to class member as a template parameter

In c++17, with the addition of auto in template arguments (P0127), I think you can now do: template<auto value> struct MyStruct {}; template<typename Class, typename Result, Result Class::* value> struct MyStruct<value> { // add members using Class, Result, and value here using containing_type = Class; }; typename MyStruct<&Something::theotherthing>::containing_type x = Something();

Can returning a local variable by value in C++11/14 result in the return value being constructed by rvalue when no copy/move is involved?

The rule for this situation changed between 2011 and 2014. The compiler should now treat localB as an rvalue. The applicable rule for return statements is found in §12.8 [class.copy]/p32, which reads in C++14 (quoting N3936, emphasis mine): When the criteria for elision of a copy/move operation are met, but not for an exception-declaration, and … Read more

Initializing a std::unique_ptr by passing the address of the pointer

Somewhere under the covers, unique_ptr<foo> has a data member of type foo*. However, it’s not legitimate for a user of the class to directly modify that data member. Doing so would not necessarily preserve the class invariants of unique_ptr, in particular it wouldn’t free the old pointer value (if any). In your special case you … Read more

Should I mark a compiler-generated constructor as constexpr?

Since the implicit constructor is actually constexpr in your case… [C++11: 12.1/6]: [..] If that user-written default constructor would satisfy the requirements of a constexpr constructor (7.1.5), the implicitly-defined default constructor is constexpr. [..] [C++11: 7.1.5/3]: The definition of a constexpr function shall satisfy the following constraints: it shall not be virtual (10.3); its return … Read more

std::string with no free store memory allocation

Andrei Alexandrescu, C++ programmer extraordinaire who wrote “Modern C++ Design” once wrote a great article about building different string implementations with customizable storage systems. His article (linked here) describes how you can do what you’ve described above as a special case of a much more general system that can handle all sorts of clever memory … Read more

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