You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
895 B
51 lines
895 B
12 years ago
|
#include <vector>
|
||
|
#include <map>
|
||
|
#include <iostream>
|
||
|
|
||
|
#include "counting_iterator.hpp"
|
||
|
#include "tuple_element.hpp"
|
||
|
|
||
|
void counting_iterator(){
|
||
|
std::vector<int> v{1,3,37,1337,7};
|
||
|
|
||
|
for(auto x : counted(v)){
|
||
|
std::cout << "v[" << x.index << "] = " << x.value << std::endl;
|
||
|
}
|
||
|
|
||
|
for(auto x : counted(v)){
|
||
|
x.value *= x.index;
|
||
|
}
|
||
|
|
||
|
for(auto x : counted(v)){
|
||
|
std::cout << "v[" << x.index << "] = " << x.value << std::endl;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void tuple_element (){
|
||
|
std::map<int, int> m1;
|
||
|
for(int i = -5; i <= 5; ++i)
|
||
|
m1[i] = i*i;
|
||
|
|
||
|
for(auto & p : values(m1)){
|
||
|
p -= 5;
|
||
|
}
|
||
|
|
||
|
auto const & m = m1;
|
||
|
for(auto & p : values(m)){ // p is a const ref
|
||
|
std::cout << p << "\t";
|
||
|
}
|
||
|
|
||
|
std::cout << std::endl;
|
||
|
|
||
|
for(auto & p : keys(m1)){ // p is a const ref, because keys in a map are const
|
||
|
std::cout << p << "\t";
|
||
|
}
|
||
|
|
||
|
std::cout << std::endl;
|
||
|
}
|
||
|
|
||
|
int main(){
|
||
|
counting_iterator();
|
||
|
tuple_element();
|
||
|
}
|