Boost logo

Boost :

From: Oleg Abrosimov (beholder_at_[hidden])
Date: 2006-07-27 22:13:54


Jeremy Day wrote:
>
> One more idea to improve maintainability of client code:
>> class my_exceptions_handler
>> {
>> BOOST_DEFINE_EXCEPTION_HANDLER_FIRST(exception_type,
>> exception_variable, 1)
>> {
>> //code here
>> }
>> BOOST_DEFINE_EXCEPTION_HANDLER(exception_type2, exception_variable,
>> 1, 2)
>> {
>> //code here
>> }
>> BOOST_DEFINE_EXCEPTION_HANDLER(exception_type2, exception_variable,
>> 2, 3)
>> {
>> //code here
>> }
>> BOOST_DEFINE_EXCEPTION_HANDLER_LAST(exception_type,
>> exception_variable, 3)
>> {
>> //code here
>> }
>> };
>>
>> These macros automatically define exceptions list eliminating last piece
>> of code duplication. numbers are used to decorate typelist' name that is
>> already defined.
>
>
> I'm not sure that I understand the need for the _FIRST and _LAST versions of
> the BOOST_DEFINE_EXCEPTION_HANDLER macro. I also don't understand why I
> need to decorate the typelist's name. If you have some pseudocode in mind
> for the definitions of BOOST_DEFINE_EXCEPTION_HANDER_FIRST,
> BOOST_DEFINE_EXCEPTION_HANDER, and BOOST_DEFINE_EXCEPTION_HANDER_LAST I'd be
> happy to look into this.

Note different number of arguments in these macros. It describes need
for BOOST_DEFINE_EXCEPTION_HANDLER_FIRST. it defines handler and typedef
for exceptions typelist with name decorated by its last argument. (with
BOOST_PP_CAT(A, B) macro)

BOOST_DEFINE_EXCEPTION_HANDLER defines handler and defines a typedef
that extends (with mpl stuff) typedef generated by
BOOST_DEFINE_EXCEPTION_HANDLER_FIRST macro. Its third parameter is used
to restore the last defined exceptions typelist's name and last
parameter is used to decorate name of typelist generated by it's own.

BOOST_DEFINE_EXCEPTION_HANDLER_LAST defines the final exceptions
typedef. It doesn't needs parameter to decorate it, only one to know a
name of the last defined typelist name.

Note, that parameters mentioned are not restricted to be numbers, but
any sequence of numbers, letters and underscores.

Hope it helps.

Best,
Oleg Abrosimov.


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