-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

> Okay. I think the following code that uses the current API
> illustrates my use case well:
> 
> if (f.has_key("a", "b") { // false is not unlikely bool parsed =
> false; int val; try { val = f.get_integer("a", "b"); parsed =
> true; } catch (...) { // unlikely } if (parsed) { fun(val); //
> fun() must called only if val is parsed // This is not necessarily
> a function } } else { /* no code, not unlikely */ }
> 
> Two observations: * The keys are optional, thus exceptions can't be
> used to handle the case when a key is not present * fun() must not
> be called if the value has not been parsed correctly

But... this works just as you want with exceptions, if you rewrite
code like this (I assume fun() to be a function here):

try {
  fun(f.get_integer("a", "b"));
}
catch(Glib::KeyFileError &) { /* Not found or not parsed */ }


The same code using Optional<T> would be:

auto opt = f.get_integer("a", "b");
if(opt) {
  fun(*opt);
}


Honestly I don't see how the later is better/easier...
Event if fun() is not a function but a bunch of code, it still looks
pretty much the same.
I look at all of this from practical POV: I want to write less/simpler
code. Your proposal replaces exception by wrapper object, but I can't
quickly think of a case where that would make code smaller or simpler,
it just replaces one thing with another.
Note: I'm not big fan of exceptions myself, so I'm not in defense of them.

- -- 
Aurimas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.15 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJSvKjTAAoJECtTeRAzEaLPeVkH/2tcesphm5lGpB92ap6sQPJj
LgNXz3Ykh42O4iOyNsPBXJjmLYpvG38BVsNK32alxj1BV+STQg3oyli25jiidC8N
QM8k5b8gKR5/GvQU1tNyoxmus8ExXeDuCjz+PfKtd785kG5Wg1+Ugj5OP+bAPlkD
MIyxR0HwAImHSV/MzdAPS+m0ZPJvsWRYB62oacfU+pMRzqJOP5ZPi7JAyPoNsnzK
HUWzyhuiYVM5d/U5ToT6K0SSOMds9ubw/Im4eaxH8BM6Yv3htMk6FK3HBXTVKoaU
orZmI7k9wmAkr3OQwW/0ALjeozkyizwLo4YZyTRdzhGydRe1fwgVbk71AtTQUrw=
=gbfn
-----END PGP SIGNATURE-----
_______________________________________________
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list

Reply via email to