Boost logo

Boost :

From: Steven Watanabe (steven_at_[hidden])
Date: 2007-12-03 10:52:20


Alexander Nasonov <alnsn <at>> writes:

> Wow! I like it. I haven't implemented it yet but the sketch looks absolutely
> correct.

There's a little problem. How to get the arguments from the
opening macro to the closing one without interfering with
another local function. I think I've found a solution for
that, too. The key is that we need to declare a variable
if it has not yet been declared. We can test whether it has
been declared by creating a global with the same name and
using a sizeof expression. So, now we need some syntax
that will be either a declaration or something else depending
on a boolean condition. To do this we can take advantage of
the ambiguity that requires the ::template syntax for dependent

typedef char no;
struct yes { no dummy[2]; };

struct conditional_declare;

struct undeclared {};

struct conditional_declare<true> {
    struct apply {
        void* value;
        friend void operator>(bool, const apply&) {}

struct conditional_declare<false> {
    static const int apply = 0;

template<class T>
yes is_declared(const T&);
no is_declared(const undeclared&);

undeclared local_function_bound_args;

     conditional_declare<sizeof(is_declared(local_function_bound_args)) == \
     sizeof(no)>::apply<0> local_function_bound_args

int main() {
    BOOST_LOCAL_FUNCTION_DECLARE_ARGS(); // declares local_function_bound_args
    BOOST_LOCAL_FUNCTION_DECLARE_ARGS(); // turns into a pair of comparisons

In Christ,
Steven Watanabe

Boost list run by bdawes at, gregod at, cpdaniel at, john at