|
Boost : |
From: Gary Powell (powellg_at_[hidden])
Date: 2002-03-26 17:04:37
Asger Alstrup Nielsen wrote:
So the ball is back in your court: Why should LL include the advanced
statement and exception support? I truly hope you can convince me that it is
a
good idea, and that the needed language support to make it great is
realistic
to achieve.
------------------------
Gary Powell Responds:
Because in small lambda programs each is extremely useful. It's when you
concatenate _ALL_ the features together that you would have been better off
writing a subroutine or functor.
For instance: to traverse a matrix, and count the number of items less than
a particular number. (and I'm going to suggest some Phoenix style coding
here.
because that's the direction we appear to be headed.
int i = 0;
std::for_each(begin, end,
for_each_(_1->*begin,
_1->*end)
[
if (_1 < N)
[
++i;
]
]
);
----------------------------------
Initialize an existing container with something that may throw if out of
memory, with the pointer, or a "smaller version", or zero. Unless a
catastrophic error occurs in which case pass it back.
std::for_each(begin, end,
try_
[
_1 = new_<BigResourceType>(_1->*getBigResourceName() )
]
.catch_<std::bad_alloc>
[
try_
[
_1 = new_<SmallResourceType>(_1->*getSmallResourceName() )
]
.catch_<std::bad_alloc>
[
_1 = 0
]
.catch_all_
[
throw_
]
]
);
---------------------------------
Pretty easy to read.
I'll grant you that the compiler errors are difficult to decipher, but with
any new technique its worth having access to it to play with in increasingly
more production like situations. First, it was available only from LL, now
it can be available from boost to a wider audience.
The more use it gets the better the library will be.
This isn't the proposal to the standards committee, its the test bench. It's
a collection of useful libraries and LL is useful.
This is no more difficult to learn than it is to learn to use STL. In fact
it makes using STL algorithms much easier.
Yours,
-Gary-
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk