Output parameters in C++ are generally considered a code smell according to the core guidelines. Yet, we have such functions in the regular expressions library
template< class BidirIt,
class Alloc, class CharT, class Traits >
bool regex_match( BidirIt first, BidirIt last,
std::match_results<BidirIt,Alloc>& m,
const std::basic_regex<CharT,Traits>& e,
std::regex_constants::match_flag_type flags =
std::regex_constants::match_default );
in which m is an output parameter. Is there a specific reason for breaking the core guidelines here and not simply returning the std::match_results by value?
regex_match()being an overloaded function, with variants not returning a match result at all. Hence a bool was used as a return value.bool(to indicate if a match is found). Among other things that avoids forcing the caller to do a relatively expensive check if the set of matches (output parameter) is empty