, , . ?
void needs_restricted_string( std::string const &str ) {
if ( ! is_restricted_string( str ) ) throw std::runtime_error( "bad str" );
…
}
, , , . , is_restricted_string() , - , , . . , .
class restricted_string {
std::string storage;
public:
restricted_string( std::string const & ) throw runtime_error;
std::string const &str() const { return storage; }
};
void needs_restricted_string( restricted_string const &str ) {
std::string const &known_restricted = str.str();
}
std::string mystr( "hello" );
needs_restricted_string( mystr );