thing->field.with([&](Field& field) {
use(field);
});
would become {
auto field = Mutex.locker(thing.field); // or thing.field.lock();
use(field);
}
or use(Mutex.locker(thing.field));
Yes, that requires you to understand destructors exist, but if you’re programming C++, that’s a given.I find that easier to understand (partly because the first doesn’t mention ‘lock’. I don’t think ‘with’ is the best name there)