Why do C++17 structured bindings not use { }?

The National Bodies from Spain and US have proposed to change back to the {} syntax because (P0488R0): The “structured bindings” proposal originally used braces “{}” to delimit binding identifiers. Those delimiters were changed to brackets “[]” under the assertion that they didn’t introduce any syntactic problem. However, they turned out to introduce syntactic ambiguity … Read more

Why is there no implicit conversion from std::string_view to std::string?

The problem is that std::string_view -> std::string makes a copy of the underlying memory, complete with heap allocation, whereas the implicit std::string -> std::string_view does not. If you’ve bothered to use a std::string_view in the first place then you obviously care about copies, so you don’t want one to happen implicitly. Consider this example: void … Read more

Compile-time or runtime detection within a constexpr function

It is possible to detect if a given function-call expression is a constant expression, and thereby select between two different implementations. Requires C++14 for the generic lambda used below. (This answer grew out this answer from @Yakk to a question I asked last year). I’m not sure how far I’m pushing the Standard. This is … Read more

Multiple SFINAE class template specialisations using void_t

There is a rule that partial specializations have to be more specialized than the primary template – both of your specializations follow that rule. But there isn’t a rule that states that partial specializations can never be ambiguous. It’s more that – if instantiation leads to ambiguous specialization, the program is ill-formed. But that ambiguous … Read more

Can std::launder be used to convert an object pointer to its enclosing array pointer?

This depends on whether the enclosing array object is a complete object, and if not, whether you can validly access more bytes through a pointer to that enclosing array object (e.g., because it’s an array element itself, or pointer-interconvertible with a larger object, or pointer-interconvertible with an object that’s an array element). The “reachable” requirement … Read more

Variadic deduction guide not taken by g++, taken by clang++ – who is correct?

This is gcc bug 80871. The issue is, we end up with this set of candidates for deduction: template <class… Types, class… Args> list<Types…> __f(Args… ); // constructor template <class… Args> list<Args…> __f(Args… ); // deduction-guide Both are valid (Types… can deduce as empty in the first case), but the call here should be ambiguous … Read more

Why is std::iterator deprecated?

From the proposal that suggested its deprecation: As an aid to writing iterator classes, the original standard library supplied the iterator class template to automate the declaration of the five typedefs expected of every iterator by iterator_traits. This was then used in the library itself, for instance in the specification of std::ostream_iterator: template <class T, … Read more

tech