C++: is string.empty() always equivalent to string == “”?

前端 未结 7 1777
灰色年华
灰色年华 2020-12-28 12:18

Can I make an assumption that given

std::string str;
... // do something to str

Is the following statement is always true?

         


        
7条回答
  •  情歌与酒
    2020-12-28 12:25

    Normally, yes.

    But if someone decides to redefine an operator then all bets are off:

    bool operator == (const std::string& a, const char b[])
    {
        return a != b; // paging www.thedailywtf.com
    }
    

提交回复
热议问题