
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] ); }
I asked on c++std-lib and Nikolay Ivchenkov suggested: #define CONSTEXPR_CHECKER(condition, expr, failure_handler) \ ((condition) ? expr : ((failure_handler), void(), expr)) and then CONSTEXPR_CHECKER( i < size(), elems[i], assert(i < size()) ); I think that there's no point in repeating the expression, so maybe #define BOOST_CONSTEXPR_ASSERT(cond, expr) \ ((cond)? expr: (BOOST_ASSERT(expr), expr)) constexpr const_reference operator[]( size_type i ) const { return BOOST_CONSTEXPR_ASSERT( i < size(), elems[i] ); } Similarly for _MSG. Or even #define BOOST_CONSTEXPR_ASSERT(cond, expr) \ ((cond)? expr: (BOOST_ASSERT_MSG(expr, #expr " requires " #cond), expr))