1// string::begin/end
2#include <iostream>
3#include <string>
4
5int main ()
6{
7 std::string str ("Test string");
8 for ( std::string::iterator it=str.begin(); it!=str.end(); ++it)
9 std::cout << *it << endl;
10 std::cout << '\n';
11
12 return 0;
13}
1//Iterator Pointer like Structore in c++ of STL
2#include <bits/stdc++.h>
3using namespace std;
4
5int main(){
6 vector<int> v = {1,2,3,4,5};
7 for(int i = 0; i<v.size(); i++){
8 cout<<v[i]<<" ";
9 }
10 cout<<endl;
11
12 vector<int> :: iterator it;
13 // it = v.begin();
14 // cout<<(*it+1)<<endl;
15
16 for(it = v.begin(); it !=v.end(); ++it){
17 cout<<(*it)<<endl;
18 }
19 cout<<endl;
20
21 vector<pair<int, int>> v_p = {{1,2},{3,4},{5,6}};
22 vector<pair<int ,int>> :: iterator iter;
23 for(iter = v_p.begin(); iter !=v_p.end(); ++iter){
24 cout<<(*iter).first<<" "<<(*iter).second<<endl;
25 }
26 cout<<endl;
27 for(iter = v_p.begin(); iter !=v_p.end(); ++iter){
28 cout<<(iter->first)<<" "<<(iter->second)<<endl;
29 }
30
31 return 0;
32}
1#include <tuple>
2#include <iostream>
3#include <boost/hana.hpp>
4#include <boost/hana/ext/std/tuple.hpp>
5
6struct Foo1 {
7 int foo() const { return 42; }
8};
9
10struct Foo2 {
11 int bar = 0;
12 int foo() { bar = 24; return bar; }
13};
14
15int main() {
16 using namespace std;
17 using boost::hana::for_each;
18
19 Foo1 foo1;
20 Foo2 foo2;
21
22 for_each(tie(foo1, foo2), [](auto &foo) {
23 cout << foo.foo() << endl;
24 });
25
26 cout << "foo2.bar after mutation: " << foo2.bar << endl;
27}
28