Advertisement
devincpp

range_based_for_loop

Sep 15th, 2023 (edited)
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <boost/type_index.hpp>
  4. using namespace std;
  5. using boost::typeindex::type_id_with_cvr;
  6.  
  7. int main()
  8. {
  9.     vector<int> vec{100};
  10.  
  11.     for (auto ele : vec)
  12.         cout << type_id_with_cvr<decltype(ele)>() << endl; // int
  13.     for (const auto &ele : vec)
  14.         cout << type_id_with_cvr<decltype(ele)>() << endl; // int const&
  15.     for (auto &&ele : vec) {
  16.         cout << type_id_with_cvr<decltype(ele)>() << endl; // int &
  17.         ++ele;
  18.         cout << vec.front() << endl; // 101
  19.     }
  20.     return 0;
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement