float multiplier[] = { -1, 1}; int i = 0; int j = 0; std::for_each(dataPoints.begin(), dataPoints.end(), [&](PointAffinity dataPoint) { pData.m_driveValue = bands[dataPoint.side][j] * multiplier[sourceSelect] * 7.0f; pData.position = dataPoint.position; i++; if(i % 2 == 0) j++; } );
Something about being able to write that inline is rather nice [smile]
Then there is always this little bit of fun;
int counter = 0; float multiplier = 1.0f; std::for_each(dataPoints.begin(), dataPoints.end(), [&](PointAffinity &point) { point.incAmount *= multiplier; if(point.side == 0) { ++counter; } if(counter % 2) { multiplier += 0.2f; } });
And having 'bind' as part of the std namespace is nice as well;
struct ID3D11CommandList;struct ID3D11DeviceContext;typedef std::function<void (ID3D11DeviceContext*)> deferredFunction_t;struct RendererCommand{ RendererCommand() : cmdID(EDrawingCommand_NOP), cmd(NULL), time(0) {}; RendererCommand(DrawingCommandType cmdID, ID3D11CommandList * cmd, DWORD time); RendererCommand(DrawingCommandType cmdID, const deferredFunction_t &function, DWORD time); RendererCommand(const RendererCommand &rhs); ~RendererCommand(); DrawingCommandType cmdID; ID3D11CommandList * cmd; deferredFunction_t deferredFunction; DWORD time;};RendererCommand DeferredComputeWrapper(const std::function<void (ID3D11DeviceContext*)> &func, ID3D11DeviceContext * context){ func(context); ID3D11CommandList * command = NULL; context->FinishCommandList(FALSE, &command); return RendererCommand(EDrawingCommand_Render, command, 0);}RendererCommand computeCmd = DeferredComputeWrapper(std::bind(UpdateCompute, width, height,_1), g_pDeferredContext);Concurrency::send(commandList, computeCmd);// or evenConcurrency::send(commandList, RendererCommand(EDrawingCommand_Function, std::bind(UpdateCompute, width, height, _1), 2));
Yeah, I think me and VS2010 + C++0x are going to get along just fine... [grin]