$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Hans Dembinski (hans.dembinski_at_[hidden])
Date: 2023-01-09 17:33:26
Dear all,
a user noticed that some classes in Boost.Histogram do not provide a strong exception guarantee, although with a few changes they could. I never promised that guarantee for those classes, but I am inclined to support it.
To that end, I am considering use a type called delayed_forward to the public interface of that class. I would like to get a mini-review on the concept. The change is backward-compatible and it offers some advantages, so it seems like a good solution to me, but maybe I am missing some caveats.
The constructor of my class, letâs call it Foo, accepts some potentially non-trivial parameters by value, because I didnât want to write an interface with a templated forward reference. Passing non-trivial parameters by value is cheap if the compiler can do RVO or if the user calls the move constructor via std::move. Not using a forward reference saves a few template instantiations and thus reduces compile time. I think I got that from Herb Sutter in a GotW entry, but I cannot find it right now.
With delayed_forward one can efficiently pass values to Foo with a single ctor. The trade-off is a tiny runtime cost, but thatâs ok if we know that Foos are not created en mass in a hot loop. That already guided my choice of passing by value.
A minimal demo is here:
https://godbolt.org/z/z71E1jno1
The design of delayed_forward is so simple that it probably already exists somewhere, likely under another name. Maybe even in Boost.
What do you think?
Hans