Lambda passed to template not defined

It seems to me this is a compiler glitch. Using Clang compiler of Visual Studio 2017 only this error is generated “cannot refer to class template ‘foo’ without a template argument list” for a and b instantiation in main function. If the function type is specified as template parameter, there are no warnings and no … Read more

Should new C++ code use memory resources instead of allocators?

At this point no. Allocators in C++ currently are much easier than they used to be. They provide both pmr (polymorphic) and classic allocator support. More importantly, pmr based allocation has not been in heavy use for years. Any weaknesses may still come to light. Fast pool based allocators, or even fixed buffer ones or … Read more

Constructor conditionally marked explicit

The proposal that added that N4387: Improving pair and tuple, revision 3 has an example of how it works: Consider the following class template A that is intended to be used as a wrapper for some other type T: #include <type_traits> #include <utility> template<class T> struct A { template<class U, typename std::enable_if< std::is_constructible<T, U>::value && … Read more

Local reference to std::cout captured by lambda without asking for it

There’s an open clang report that cover the case of implicit capture of references by lambda expressions, this is not limited to std::cout but to references variable that are found to refer to constant expressions. For more reference, the backing defect report on the CWG is CWG-1472 EDIT: Based on @Rakete1111 comment, I should have … Read more

What is the reason for `std::result_of` deprecated in C++17?

T.C. already provided the obvious link, but perhaps the most horrific reason bears repeating: result_of involved forming the type F(Arg1, Arg2, …) not for a function of those types returning F but for a function of type F accepting those types. (After all, the return type is the result of, well, result_of, not the input!) … Read more

Does the definition int a = 0, b = a++, c = a++; have defined behavior in C?

Does the definition int a = 0, b = a++, c = a++; have defined behavior in C? Yes, because C 2018 6.8 3 says these initializations (not all, see bottom) are evaluated in the order they appear: … The initializers of objects that have automatic storage duration, and the variable length array declarators of … Read more

Why is partial class template argument deduction impossible?

From this excellent trip report by Botond Ballo: The feature as originally proposed included a provision for partial deduction, where you explicitly specify some of the template arguments, and leave the rest to be deduced, but this was pulled over concerns that it can be very confusing in some cases: // Would have deduced tuple<int, … Read more

When should I use std::any

When to Use void* as an extremely unsafe pattern with some limited use cases, std::any adds type-safety, and that’s why it has some real use cases. Some possibilities: In Libraries – when a library type has to hold or pass anything without knowing the set of available types. Parsing files – if you really cannot … Read more