|
Boost : |
From: Alexander Nasonov (alnsn_at_[hidden])
Date: 2007-04-04 16:41:49
Hans Larsen wrote:
> or, putting the code as a parameter to the macro:
>
> BOOST_SCOPE_EXIT( (hello)(world),
> {
> // ...
> } );
As Andrey pointed out, any comma inside the block would break your code:
BOOST_SCOPE_EXIT( (hello)(world), { a, b; } )
GNU g++ would report something like:
macro "BOOST_SCOPE_EXIT" passed 3 arguments, but takes just 2.
You could either
BOOST_SCOPE_EXIT( (hello)(world), ({ a, b; }) )
or
BOOST_SCOPE_EXIT( (hello)(world), { (a, b;) } )
but I don't know how to deal with these strange constructs.
> What about using a static variable instead?
It has no significant differences with a global variable.
> // User code
> //BOOST_SCOPE_EXIT( (hello)(world) ) // line 1
> /* Expands to: */
> static struct args_line1_t { std::string &hello, &world; }
> args_line1 = { hello, world };
It's incorrect, args_line1 is initialized only once and never
changes. It always points to hello and world existed when a program
reached this point the first time.
> Is the use of __LINE__ correct? I can't think of a way to break it,
> which in no way means it's perfect...
It's correct unless you put more than one scope(exit) in one line.
> >>>> Why do you need that library and is it absolutely necessary?
> >>> Because I saw so much exception unaware code.
> >> I don't see any case of valid exceptions in the use of this library.
> > Sorry, I don't understand this statement.
>
> Simply that
> BOOST_SCOPE_EXIT( ... )
> {
> throw XXX;
> }
>
> Is invalid by definition.
Indeed, it's almost always invalid. I would never throw from inside
of a scope(exit) block.
But I was talking about exception unware code in pre scope(exit)
era. Developers often don't cleanup resources if an exception is
thrown. The library would help here.
> If you're talking about the fact that you need to get an unknown
> typename into a local-class (how to know that hello and world are
> std::string, for example), then the typeof dependency is well
> justified. Otherwise, I still fail to see why it is needed.
Yes, typeof is there to bring types of variables into the class.
-- Alexander Nasonov http://nasonov.blogspot.com Government does not tax to get the money it needs; government always finds a need for the money it gets. -- Ronald Reagan -- This quote is generated by: /usr/pkg/bin/curl -L http://tinyurl.com/veusy \ | sed -e 's/^document\.write(.//' -e 's/.);$/ --/' \ -e 's/<[^>]*>//g' -e 's/^More quotes from //' \ | fmt | tee ~/.signature-quote
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk