1/*
2 * Copyright (c) 2014 ETH Zurich.
3 * All rights reserved.
4 *
5 * This file is distributed under the terms in the attached LICENSE file.
6 * If you do not find this file, copies can be found by writing to:
7 * ETH Zurich D-INFK, Universitaetsstrasse 4, CH-8092 Zurich. Attn: Systems Group.
8 */
9
10#include <iostream>
11#include <vector>
12#include <map>
13
14#include "cxxtest.hpp"
15
16using namespace std;
17
18static void cx11_lambda_test(void)
19{
20    cout << "cx11 lambda" << endl;
21
22    std::vector<int> v;
23    v.push_back(1);
24    v.push_back(2);
25    v.push_back(3);
26
27    std::for_each(std::begin(v), std::end(v), [](int n) {std::cout << n << std::endl;});
28
29    auto is_odd = [](int n) {return n%2==1;};
30    auto pos = std::find_if(std::begin(v), std::end(v), is_odd);
31    if(pos != std::end(v))
32      std::cout << *pos << std::endl;
33}
34
35static void cx11_ranged_forloop_test(void)
36{
37    cout << "cx11 ranged forloop" << endl;
38
39    std::map<std::string, std::vector<int>> map;
40    std::vector<int> v, v2;
41    v.push_back(1);
42    v.push_back(2);
43    v.push_back(3);
44    v2.push_back(4);
45    v2.push_back(5);
46    v2.push_back(6);
47    v2.push_back(7);
48    map["one"] = v;
49    map["two"] = v2;
50
51    for(const auto& kvp : map)
52    {
53      std::cout << kvp.first << std::endl;
54
55      for(auto val : kvp.second)
56      {
57         std::cout << " " << val << std::endl;
58      }
59    }
60
61    int arr[] = {1,2,3,4,5};
62    for(int& e : arr)
63    {
64      e = e*e;
65    }
66}
67
68void cx11_test(void)
69{
70    cout << "cx11_test" << endl;
71
72    cx11_ranged_forloop_test();
73    cx11_lambda_test();
74}
75