std::transform using C++0x lambda expression
std::transform(myv1.begin(), myv1.end(), myv1.begin(), [](double d) -> double { return d * 3; });
std::transform(myv1.begin(), myv1.end(), myv1.begin(), [](double d) -> double { return d * 3; });
I think according to the C++11 standard, this should be supported Not really, because a non-static member function has an implicit first parameter of type (cv-qualified) YourType*, so in this case it does not match void(int). Hence the need for std::bind: Register(std::bind(&Class::Function, PointerToSomeInstanceOfClass, _1)); For example Class c; using namespace std::placeholders; // for _1, _2 … Read more
In C++14 thanks to generalized lambda captures you can do something like so: std::vector<int> v(10); std::for_each(v.begin(), v.end(), [idx = 0] (int i) mutable { // your code… ++idx; // 0, 1, 2… 9 });
No, there’s nothing wrong with your design, and it’s the normal approach taken for this sort of problem. It’s perfectly valid for you to have multiple conditions (eg anything on queue or program stopping) attached to a condition variable. The key thing is that the bits in the condition are checked for when the wait … Read more
I just learned today that there was one (somewhat) significant change between N1570 and the final C11 standard (ISO/IEC 9899:2011 (E)). In N1570, 6.3.2p3 says: Except when it is the operand of the sizeof operator, the _Alignof operator, or the unary & operator, or is a string literal used to initialize an array, an expression … Read more
What leads me to this thought is that even the MS C++AMP blogs have been silent for about a year. Looking at the C++ AMP algorithms library http://ampalgorithms.codeplex.com/wikipage/history it seems nothing at all has happened for over a year. I used to work on the C++AMP algorithms library. After the initial release, which Microsoft put … Read more
Yes, *this is always an lvalue, no matter how a member function is called, so if you want the compiler to treat it as an rvalue, you need to use std::move or equivalent. It has to be, considering this class: struct A { void gun() &; // leaves object usable void gun() &&; // makes … Read more
It looks like 3.7 supports something like this (haven’t tested yet). From the docs AlignConsecutiveAssignments (bool) If true, aligns consecutive assignments. This will align the assignment operators of consecutive lines. This will result in formattings like code int aaaa = 12; int b = 23; int ccc = 23; endcode (sic)
Your second case is undefined behavior, you are no longer using aggregate initialization, it is still list initialization but in this case you have a user defined constructor which is being called. In order to pass the second argument to your constructor it needs to evaluate foo.i but it is not initialized yet since you … Read more
The standard containers all return references from their iterator (note, however, that some “containers aren’t really container, e.g., std::vector<bool> which returns a proxy). Other iterators might return proxies or values although this isn’t strictly supported. Of course, the standard doesn’t make any guarantees with respect to performance. Any sort of performance related feature (beyond complexity … Read more