WaltK
WaltK

Reputation: 774

For what reason would a function with void return type be constexpr?

To give a specific example, the push_back() member functions of std::vector became constexpr in C++20.

https://en.cppreference.com/w/cpp/container/vector/push_back

Upvotes: 2

Views: 223

Answers (1)

Sam Varshavchik
Sam Varshavchik

Reputation: 118425

One of the requirements of a constexpr function is that it can only call other constexpr functions.

So, this allows push_back() to be called from some other constexpr function that might, actually, return something useful.

Upvotes: 5

Related Questions