1 #include "IfAndSwitchInitStatements.h"
8 // Ep 21: https://www.youtube.com/watch?v=AiXU5EuLZgc
10 namespace IfAndSwitchInitStatements
12 vector
<int> make_vec()
14 return { 1, 2, 3, 4 };
18 void IfAndSwitchInitStatements::tests()
20 auto vec
= make_vec();
22 // Same for 'switch' block.
23 if (const auto itr
= find(vec
.begin(), vec
.end(), 2);
33 // Declare an variable into a if condition allows to use this variable only in the if scope
34 // and will not get out of scope.
35 // Here we can reuse the name 'itr' previously used in the previous if statement.
36 if (const auto itr
= find(vec
.begin(), vec
.end(), 3);
46 for (auto i
= vec
.begin(); i
!= vec
.end(); ++i
)