polymorphic_allocator: when and why should I use it?

Choice quote from cppreference: This runtime polymorphism allows objects using polymorphic_allocator to behave as if they used different allocator types at run time despite the identical static allocator type The issue with “regular” allocators is that they change the type of the container. If you want a vector with a specific allocator, you can make … Read more

How do inline variables work?

The first sentence of the proposal: ” The ​inline specifier can be applied to variables as well as to functions. The ¹guaranteed effect of inline as applied to a function, is to allow the function to be defined identically, with external linkage, in multiple translation units. In practice that means defining the function in a header, that can be included in multiple translation units. The proposal … Read more

How to enable C++17 compiling in Visual Studio?

There’s now a drop down (at least since VS 2017.3.5) where you can specifically select C++17. The available options are (under project > Properties > C/C++ > Language > C++ Language Standard) ISO C++14 Standard. msvc command line option: /std:c++14 ISO C++17 Standard. msvc command line option: /std:c++17 Visual Studio 2022 (MSVC C++20 and the … Read more

What made i = i++ + 1; legal in C++17?

In C++11 the act of “assignment”, i.e. the side-effect of modifying the LHS, is sequenced after the value computation of the right operand. Note that this is a relatively “weak” guarantee: it produces sequencing only with relation to value computation of the RHS. It says nothing about the side-effects that might be present in the … Read more

What is string_view?

The purpose of any and all kinds of “string reference” and “array reference” proposals is to avoid copying data which is already owned somewhere else and of which only a non-mutating view is required. The string_view in question is one such proposal; there were earlier ones called string_ref and array_ref, too. The idea is always … Read more

std::lock_guard or std::scoped_lock?

The scoped_lock is a strictly superior version of lock_guard that locks an arbitrary number of mutexes all at once (using the same deadlock-avoidance algorithm as std::lock). In new code, you should only ever use scoped_lock. The only reason lock_guard still exists is for compatibility. It could not just be deleted, because it is used in … Read more

enum to string in modern C++11 / C++14 / C++17 and future C++20

(The approach of the better_enums library) There is a way to do enum to string in current C++ that looks like this: ENUM(Channel, char, Red = 1, Green, Blue) // “Same as”: // enum class Channel : char { Red = 1, Green, Blue }; Usage: Channel c = Channel::_from_string(“Green”); // Channel::Green (2) c._to_string(); // … Read more

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