On 31.05.20 18:03, Christian Mazakas via Boost wrote:
The use of such a low-level API would look something like this:
Hmm, I'm failing to see the overwhelming value in exposing these portions
of the API.
Here is one use case for some kind of low-level access to error objects
without going through lambdas (although it would have a different form
than the one used by Bjorn). Suppose I have an error type that may or
may not be annotated with a file name, an IP address, or a user name,
individually or in any combination. For each of these annotations, I
want to handle it the same whenever it is present, regardless of the
others. Without some sort of direct access to error objects, the code
for this would look something like this:
return leaf::try_handle_some(
some_try_block,
[](leaf::match,
leaf::e_file_name fname,
my::e_user_name uname,
my::ip_address ip) {
handle_filename(fname);
handle_user_name(uname);
handle_ip(ip);
return handle_error();
},
[](leaf::match,
leaf::e_file_name fname,
my::e_user_name uname) {
handle_filename(fname);
handle_user_name(uname);
return handle_error();
},
[](leaf::match,
leaf::e_file_name fname,
my::ip_address ip) {
handle_filename(fname);
handle_ip(ip);
return handle_error();
},
[](leaf::match,
leaf::e_file_name fname) {
handle_filename(fname);
return handle_error();
},
[](leaf::match,
my::e_user_name uname,
my::ip_address ip) {
handle_user_name(uname);
handle_ip(ip);
return handle_error();
},
[](leaf::match,
my::e_user_name uname) {
handle_user_name(uname);
return handle_error();
},
[](leaf::match,
my::ip_address ip) {
handle_ip(ip);
return handle_error();
},
[](leaf::match) {
return handle_error();
});
That's a lot of redundant code that could be avoided if I had a way to
query at runtime if a particular annotation is present or not.
--
Rainer Deyke (rainerd@eldwood.com)