Boost logo

Boost :

Subject: Re: [boost] Boost.Local Review (Nov 10, 2011 to Nov 19, 2011)
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2011-11-14 06:59:38


Hello all,

I have received a couple of questions on Boost.Local and I will answer
them on the ML.

On Mon, Nov 14, 2011 at 4:20 AM, Andrzej Krzemienski <akrzemi1_at_[hidden]> wrote:
> 1. Can Boost.Local be used to create global functions?

No, Boost.Local macros need to be used at local scope. If it were
important to use the functionality of Boost.Local at global scope, it
_might_ be possible to do so but another set of macros
(BOOST_GLOBAL_?) will have to be defined for that.

Does anyone see a need to use LOCAL_EXIT, LOCAL_BLOCK, or
LOCAL_FUNCTION at global scope? If so, why?

> 2. For Local Exits, is it possible not to bind any variable (because I will
> only be calling global functions):
>
> int runCommand() {
>     ::DisplayWaitCursor();
>     BOOST_LOCAL_EXIT( /*nothing*/ ) {
>         ::DisplayNormalCursor();
>     } BOOST_LOCAL_EXIT_END;
>
>     DoALongLastingOperation();
> }

Yes, you can do this. However, the most portable syntax is to use void
for the empty parameter list:
https://svn.boost.org/svn/boost/sandbox/local/libs/local/doc/html/boost_local/Tutorial.html#boost_local.Tutorial.Empty_Parameters

For example:

#include <boost/local/exit.hpp>
#include <iostream>

void f() {
    std::cout << "f" << std::endl;
}

int main() {
    ::f();
    BOOST_LOCAL_EXIT(void) {
        ::f();
    } BOOST_LOCAL_EXIT_END
    return 0;
};

This compiles and it prints "f" twice (at main entry and exit).

HTH,
--Lorenzo


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