If (VEC. End () = Vec. Erase (VEC. Begin (), VEC. End () is not necessarily true!

Source: Internet
Author: User

If (VEC. End () = Vec. Erase (VEC. Begin (), VEC. End () <br/>

According to the definition of msdn and Vc, this expression must be true,

Because VC calculates erase (right expression) First, the returned value must be end, and then end () is calculated. The returned value is the same as the returned value of erase.

However, in fact

Debug version execution is true

Release Version execution isFalse!

 

In the release version, VEC. End () is optimized to be a value obtained first, and then erase is calculated,

Erase will change the end value.

Therefore, the release version must be written in this way:

Iter = Vec. erase (VEC. begin (), VEC. end () <br/> // The above forces the calculation of erase first <br/> If (VEC. end () = ITER) // The end () value is equal. <br/>

 

The first statement made two serious mistakes:

1. incorrect assumptions based on experienceCalculate the value of the expression from right to left during logical operations (C ++ is not specified and may be optimized)

2. The end () return value is a constant.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.