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

前端 未结 7 1778
灰色年华
灰色年华 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:36

    Some implementations might test for the null character as the first character in the string resulting in a slight speed increase over calculating the size of the string.

    I believe that this is not common however.

提交回复
热议问题