Using std::make_unique with a custom deleter

The whole point of make_unique is to encapsulate the notion of “use new to create a T from given constructor arguments and use delete to destroy it”. If you wanted a custom deleter, you would also have to specify how to create the object, and then there would be nothing more gained from having the … Read more

Is C++20 ‘char8_t’ the same as our old ‘char’?

Disclaimer: I’m the author of the char8_t P0482 and P1423 proposals. In C++20, char8_t is a distinct type from all other types. In the related proposal for C, N2653, char8_t is a typedef of unsigned char similar to the existing typedefs for char16_t and char32_t. In C++20, char8_t has an underlying representation that matches unsigned … Read more

Can I legally reinterpret_cast between layout-compatible standard-layout types?

but I can’t see anything in the standard that therefore allows me to reinterpret_cast between them, even though that seems like the reasonable interpretation of “value representation”. Is this technically allowed by the standard? No. The standard is clear (see [basic.lval] p10) about which types can be aliased, and layout-compatible types are not included. If … Read more

Classes with both template and non-template conversion operators in the condition of switch statement

I believe clang is correct here. We can see from the draft C++ standard section 6.4.2 The switch statement that this involves a contextually implicit conversion. Paragraph 2 says (*emphasis mine going forward): The condition shall be of integral type, enumeration type, or class type. If of class type, the condition is contextually implicitly converted … Read more

Raw pointer lookup for sets of unique_ptrs

In C++14, std::set<Key>::find is a template function if Compare::is_transparent exists. The type you pass in does not need to be Key, just equivalent under your comparator. So write a comparator: template<class T> struct pointer_comp { typedef std::true_type is_transparent; // helper does some magic in order to reduce the number of // pairs of types we … Read more