assert returning a value in c++

99 Views Asked by At

It be very useful to have assert returning a value in c++ like this:

SomeType someValue = assert(getSomeValue());

instead of

SomeType someValue = getSomeValue();
assert(someValue);

Is there any standard way to do this?

1

There are 1 best solutions below

2
Mike Nakis On
  1. No, there is no standard way of doing this.
  2. You can easily write your own macro (assertTrue(), assertNotNull(), etc.)
  3. I would advise against this, because assertions should stand out, and the way to make something stand out is to have it occupy a line of its own.