push_back or emplace_back with std::make_unique

It doesn’t make a difference as far as construction of the new object is concerned; you already have a unique_ptr<Foo> prvalue (the result of the call to make_unique) so both push_back and emplace_back will call the unique_ptr move constructor when constructing the element to be appended to the vector. If your use case involves accessing … Read more

What is the __STDC_VERSION__ value for C11?

With -std=c11 in gcc, 201112L is used for __STDC_VERSION__ See this gcc patch on December 20, 2011 on gcc ml: https://www.mail-archive.com/gcc-patches@gcc.gnu.org/msg23572.html And note that apparently the ISO version of C11 forgot to update the 201ymmL from the Draft. The intended final __STDC_VERSION__ value, 201112L, is also implemented (the editor forgot to update the 201ymmL placeholders … Read more

C++11 observer pattern (signals, slots, events, change broadcaster/listener, or whatever you want to call it)

I think that bind makes it easier to create slots (cfr. the ‘preferred’ syntax vs. the ‘portable’ syntax – that’s all going away). The observer management, however, is not becoming less complex. But as @R. Martinho Fernandes mentions: an std::vector<std::function< r(a1) > > is now easily created without the hassle for an (artificial) ‘pure virtual’ … Read more

Nested C++ template parameters for functions

std::vector has two parameters, type and allocator. Try this template <typename T, typename Alloc, template <typename, typename> class V> void print_container(V<T, Alloc> &con) { } print_container(vec); This will work for vector, list, etc., but will not work with map, set. However, since you use auto you can use C++11 and then you can to this: … Read more

C++11 aggregate initialization for classes with non-static member initializers

In C++11 having in-class member initializers makes the struct/class not an aggregate — this was changed in C++14, however. This is something I found surprising when I first ran into it, the rationale for this restriction is that in-class initializers are pretty similar to a user defined constructor but the counter argument is that no … Read more

Advantage of using trailing return type in C++11 functions [duplicate]

In this example, they mean the exact same thing. However, there are a few advantages to using the trailing return type form consistently (Phil Nash calls these “East End Functions”, since the return type is on the east end). Using parameters. Obviously when using parameters to determine the return type, you must use a trailing … Read more

Questions about Hinnant’s stack allocator

I’ve been using Howard Hinnant’s stack allocator and it works like a charm, but some details of the implementation are a little unclear to me. Glad it’s been working for you. 1. Why are global operators new and delete used? The allocate() and deallocate() member functions use ::operator new and ::operator delete respectively. Similarly, the … Read more

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