How can I mark a C++ class method as deprecated?

In C++14, you can mark a function as deprecated using the [[deprecated]] attribute (see section 7.6.5 [dcl.attr.deprecated]). The attribute-token deprecated can be used to mark names and entities whose use is still allowed, but is discouraged for some reason. For example, the following function foo is deprecated: [[deprecated]] void foo(int); It is possible to provide … Read more

Sell me const-correctness

This is the definitive article on “const correctness”: https://isocpp.org/wiki/faq/const-correctness. In a nutshell, using const is good practice because… It protects you from accidentally changing variables that aren’t intended be changed, It protects you from making accidental variable assignments. For instance, you are protected from if( x = y ) // whoops, meant if( x == … Read more

How do memory_order_seq_cst and memory_order_acq_rel differ?

http://en.cppreference.com/w/cpp/atomic/memory_order has a good example at the bottom that only works with memory_order_seq_cst. Essentially memory_order_acq_rel provides read and write orderings relative to the atomic variable, while memory_order_seq_cst provides read and write ordering globally. That is, the sequentially consistent operations are visible in the same order across all threads. The example boils down to this: bool … Read more

Why does C++11 have `make_shared` but not `make_unique` [duplicate]

According to Herb Sutter in this article it was “partly an oversight”. The article contains a nice implementation, and makes a strong case for using it: template<typename T, typename …Args> std::unique_ptr<T> make_unique( Args&& …args ) { return std::unique_ptr<T>( new T( std::forward<Args>(args)… ) ); } Update: The original update has been updated and the emphasis has … Read more