I have a class:
class Symbol_t {
public:
Symbol_t( const char* rawName ) {
memcpy( m_V, rawName, 6 * sizeof( char ) );
};
string_view strVw() const {
return string_view( m_V, 6 );
};
private:
char m_V[6];
}; // class Symbol_t
and there is a lib-func that I can't modify:
extern bool loadData( const string& strSymbol );
If there is a local variable:
Symbol_t symbol( "123456" );
When I need to call loadData, I dare not do it like this:
loadData( string( symbol.strVw().begin(), symbol.strVw().end() ) );
I have to do like this:
string_view svwSym = symbol.strVw();
loadData( string( svw.begin(), svw.end() ) );
My question:
Is the first method correct? or I must use the second one?
Because I think that in Method 1, the iterators I passed to the constructor of std::string, are of two Different string_vew objects, and theoretically the result is undefined, even though we would get expected result with almost all of the C++ compilers.
Any hints will be appreciated! thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…