What is the modern approach when it comes to returning two values (e.g. a vector
and a bool
)?
This one:
bool tokenize( const std::string_view inputStr, const std::size_t expectedTokenCount,
std::vector< std::string >& foundTokens )
{
// fill foundTokens which has been declared in the call site
}
or this one:
auto tokenize( const std::string_view inputStr, const std::size_t expectedTokenCount )
{
std::vector< std::string > foundTokens;
// fill foundTokens which is a local variable
bool isValid = true;
return std::make_pair< bool, std::vector<std::string> >( std::move( isValid ),
std::move( foundTokens ) );
}
or maybe another approach?
Any advice is appreciated.