Category : language-lawyer

A colleague of mine suggested to read a nice post operator<=> doesn’t obsolete the hidden friend idiom Let me quote the code from there: #include <compare> struct Good { friend auto operator<=>(const Good&, const Good&) = default; }; struct Bad { auto operator<=>(const Bad&) const = default; }; static_assert(std::totally_ordered<Good>); static_assert(std::totally_ordered<Bad>); static_assert(std::totally_ordered<std::reference_wrapper<Good>>); // Clang and GCC ..

Read more

Starting from C++20 closure types without captures have default constructor, see https://en.cppreference.com/w/cpp/language/lambda: If no captures are specified, the closure type has a defaulted default constructor. But what about closure types that capture, how can their objects be constructed? One way is by using std::bit_cast (provided that the closure type can be trivially copyable). And Visual ..

Read more

Recently, after playing around with the C++20 feature of being able to pass class types in non-type template parameters (P0732R2), I’ve encountered something rather strange. Consider the following code: template <typename T> struct abc { T p; consteval abc(T p) : p(p) { } consteval operator decltype(p)() const { return p; } }; template <abc ..

Read more

Lambda’s operator() is implicitly constexpr according to https://en.cppreference.com/w/cpp/language/lambda When this specifier (constexpr) is not present, the function call operator or any given operator template specialization will be constexpr anyway, if it happens to satisfy all constexpr function requirements And a requirement of a constexpr-function according to https://en.cppreference.com/w/cpp/language/constexpr there exists at least one set of argument ..

Read more