> Coding, hacking, computer graphics, game dev, and such...
fips
Site Admin
Posts: 170 Joined: Wed Nov 12, 2008 9:49 pm
Location: Prague
Contact:
Post
by fips » Fri Jul 16, 2010 11:21 pm
Finally, a sensible way to express
Predicates .
Lambda rocks! No
Boost required any more!
Code: Select all
int ModulePool::FindByFile(const String &file) const
{
const Modules::const_iterator it = std::find_if(
modules_.begin(), modules_.end(),
[&file](const ModuleInfo &mi) { return mi.file_ == file; }
);
return it != modules_.end() ? std::distance(modules_.begin(), it) : -1;
}
fips
Site Admin
Posts: 170 Joined: Wed Nov 12, 2008 9:49 pm
Location: Prague
Contact:
Post
by fips » Sun Jul 25, 2010 1:24 pm
Another Lambda function I've just written - It initializes a static variable
vertexDeclaration with a vector of
VertexElement s constructed from an array. (It would be even easier to use
std::initializer_list for this, but it's not supported in
Visual C++ 2010 at this moment.)
Code: Select all
const VertexDeclaration VertexPositionColor::vertexDeclaration(
[]() -> VertexElementVector
{
const VertexElement elems[] = {
VertexElement(0, VEF_Vector3, VEU_Position, 0),
VertexElement(0, VEF_Color, VEU_Color, 0),
};
return VertexElementVector(
&elems[0],
&elems[sizeof(elems) / sizeof(elems[0])]
);
}());