65,186
社区成员




template<typename EventType, typename F>
std::function<void(EventType&)> wrapper(F callback)
{
return [=](EventType& e) { // 1)
if (!e.canceled)
callback(e);
};
}
template<typename EventType, typename F, typename WorldType>
std::function<void(EventType&)> world_wrapper(F callback,
std::shared_ptr<WorldType> world)
{
std::weak_ptr<WorldType> ptr(world);
return [ptr,callback](EventType& e) // 2)
{
std::shared_ptr<WorldType> world = ptr.lock();
if (world && e.world == world)
callback(e);
};
}
#include <algorithm>
#include <cmath>
void abssort(float *x, unsigned N) {
std::sort(x, x+N,
[](float a, float b) { // 注意此处的方括弧
return std::abs(a) < std::abs(b);
});
}