Why use std::type_index instead of std::type_info*

type_index is “a simple wrapper for type_info which can be used as an index type in associative containers (23.4) and in unordered associative containers (23.5)”. If you use type_index instead of type_info*, you will free yourself from having to provide an explicit comparator in your maps. The only cost is that you need to #include … Read more

Why is std::unique_ptr::reset() always noexcept?

The requirements of the call to the function object Deleter are specific on this as listed in the requirements of the std::unique_ptr<T>::reset() member. From [unique.ptr.single.modifiers]/3, circa N4660 ยง23.11.1.2.5/3; unique_ptr modifiers void reset(pointer p = pointer()) noexcept; Requires: The expression get_deleter()(get()) shall be well formed, shall have well-defined behavior, and shall not throw exceptions. In general … Read more

How to use to replace rand()?

Is there a reasonably simple way to replace srand() and rand()? Full disclosure: I don’t like rand(). It’s bad, and it’s very easily abused. The C++11 random library fills in a void that has been lacking for a long, long time. The problem with high quality random libraries is that they’re oftentimes hard to use. … Read more

Why can’t I initialize a reference in an initializer list with uniform initialization?

Yes, its a bug. This is something new and was voted in the working paper in February 2012 (link). Nicol Bolas makes a good point in that gcc is actually the conforming compiler according to the FDIS approved C++11 standard because the changes to the working paper were made after that.

What is move_iterator for

If I understand it correct, a=std::move(b) binds reference a to the address of b. And after this operation the content that b points to is not guaranteed. Ah, no: a is not necessarily a reference. The above use of std::move also grants the compiler permission to call decltype(a)::operator=(decltype(b)&&) if it exists: such assignment operators are … Read more

replacement for std::binary_function

First, my advice is to watch CppCon 2015: Stephan T. Lavavej “functional: What’s New, And Proper Usage”. std::binary_function is mentioned on slide 36, at around 36 mins in the video. You can find the slides at github.com/CppCon/CppCon2015). It doesn’t go into detail why you shouldn’t use std::binary_function, but if you’re using something that’s been deprecated … Read more

Selecting a member function using different enable_if conditions [duplicate]

enable_if works because the substitution of a template argument resulted in an error, and so that substitution is dropped from the overload resolution set and only other viable overloads are considered by the compiler. In your example, there is no substitution occurring when instantiating the member functions because the template argument T is already known … Read more

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