C++11 and the lack of polymorphic lambdas – why?

The reason we don’t have polymorphic lambdas is explained pretty well in this posting. It has to do with the concepts feature that was pulled from C++11: essentially, polymorphic lambdas are ordinary, unconstrained function templates and we didn’t know how to typecheck a concept-constrained template that used an unconstrained template. However, solving that problem turns … Read more

When moving a unique_ptr into a lambda, why is it not possible to call reset?

Why does this happen? Because the function-call operator of a lambda, Unless the keyword mutable was used in the lambda-expression, the function-call operator is const-qualified and the objects that were captured by copy are non-modifiable from inside this operator(). and Is it possible to capture the std::unique_ptr in another way which allows to call reset() … Read more

Moving an object into a map

std::map::insert has an overload for R-values: std::pair<iterator,bool> insert(value_type&&); Any expression which binds to this overload will invoke R-value constructors. Since std::map<K,V>::value_type is std::pair<const key_type, mapped_type>, and std::pair has a constructor that takes R-values: template<class U1, class U2> pair(U1&& x, U2&& y); then you are guaranteed that R-value constructors for key_type and mapped_type will be invoked, … Read more

C++11 way to index tuple at runtime without using switch

Here’s a version that doesn’t use an index sequence: template <size_t I> struct visit_impl { template <typename T, typename F> static void visit(T& tup, size_t idx, F fun) { if (idx == I – 1) fun(std::get<I – 1>(tup)); else visit_impl<I – 1>::visit(tup, idx, fun); } }; template <> struct visit_impl<0> { template <typename T, typename … Read more

Passing arguments to std::async by reference fails

It’s a deliberate design choice/trade-off. First, it’s not necessarily possible to find out whether the functionoid passed to async takes its arguments by reference or not. (If it’s not a simple function but a function object, it could have an overloaded function call operator, for example.) So async cannot say, “Hey, let me just check … Read more

How to initialize a static std::atomic data member

I know that the atomic types do not have copy constructors, and I assume that explains why this code does not work. Yes, the error says that quite clearly. Does anybody know a way to actually get this code to work? Instead of copy-initialising from a temporary, which requires an accessible copy constructor: std::atomic<int> order::c … Read more

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