Subject: Re: [boost] Boost.Exception and constexpr
From: Peter Dimov (lists_at_[hidden])
Date: 2013-01-10 06:47:28
Andrey Semashev wrote:
> I don't think that the ternary operator and a throw expression is a
> constant expression that can be used in a constexpr function. In
> 5.19/2, the throw expression is explicitly mentioned as the one that
> cannot make a constant expression.
I suspect that you've missed the
"but subexpressions of logical AND (5.14), logical OR (5.15), and
(5.16) operations that are not evaluated are not considered"
part. You can have a throw expression, as long as it's not evaluated.
> In fact, I cannot see how a constant expression (such as a constexpr
> function) can throw.
A constexpr function can throw when it's called with an argument that is not
a constant expression.
On second thought, this perhaps does make it possible to have something
assert-like in a constexpr function.
constexpr const_reference operator( size_type i ) const
return i < size()? elems[i]: ( abort(), elems[i] );
// return i < size()? elems[i]: ( abort(), throw 0 );
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk