...

/

Requirements on Return Types

Requirements on Return Types

Get an overview of the requirements on the return types.

We'll cover the following...

We’ve seen how to write a requirement expressing that certain functions must exist in a class API.

Constrain the return type

But did we constrain the return type of those functions?

template <typename T>
concept HasSquare = requires (T t) {
  t.square();
  t.sqrt();
};

No, we didn’t. A class would satisfy the constraints of the HasSquare concept with int square() and void square() both.

If we want to specify the expected return type, we must use a compound requirement. ...