Boost logo

Boost :

Subject: [boost] [Utility] intuitive scoping with BOOST_WITH
From: Marcel Ebmer (marcel_at_[hidden])
Date: 2015-08-06 20:09:47


Hi Everyone,

What if you could do

std::mutex the_mutex; using Lock = std::unique_lock<std::mutex>; void
f() { with(Lock{the_mutex}) { do_something();
do_other_thing(); } }

*...or...*

struct Pushed_matrix {
    Pushed_matrix() { glPushMatrix(); }
    ~Pushed_matrix() { glPopMatrix(); }
};

void f() {
    with(Pushed_matrix{})
        draw_something();
}

At C++Now (2015), I presented this idea of mine and a macro
implementation (BOOST_WITH) in a lightning talk. Since reception was
good and more serious than the talk itself, I continued to work on it. I
would appreciate informal review and opinions:

https://github.com/maysl/BOOST_WITH

Marcel


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk