|
Boost : |
Subject: Re: [boost] [variant2] Andrzej's review -- design
From: Peter Dimov (pdimov_at_[hidden])
Date: 2019-04-02 17:53:50
Andrzej Krzemienski wrote:
> I have started a thread in this list a while ago, requesting for an
> example of code that *correctly handles exceptions* (does not stop stack
> unwinding at random places), where the programmer would make use of the
> never-empty guarantee , and chose something else than destroying or
> resetting the variant. And although I received some generic statements,
> referring to the purity of the design, strength of the invariants, and the
> easiness of thinking or "correctness", none of the proponents of the
> never-empty guarantee gave such an example.
template<class T> class monitor
{
private:
char const* file_;
int line_;
T const& v_;
T old_;
public:
explicit monitor( char const* file, int line, T const& v ):
file_( file ), line_( line ), v_( v ), old_( v ) {}
~monitor()
{
if( v_ != old_ )
{
std::clog << file_ << ":" << line_
<< ": monitored value changed from "
<< old_ << " to " << v_ << std::endl;
}
}
};
Or in general, in a destroy-only world, you can never read any values in a
destructor or in a function called from a catch clause. It might be an
interesting experiment to make Clang warn on such a use and then try it on
some real codebases.
These reads of a potentially-destroy-only values are invisible to you
because we don't live in such a world.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk