// // main.cpp // test_enviroment // // Created by Christian Reiling on 13.03.19. // Copyright © 2019 Christian Reiling. All rights reserved. // #include #include #include #include using namespace std; //Sum Generic Container /*template double Sum(const T& cont) { double sum = 0; typename T::const_iterator iter = cont.begin(); for (iter; iter != cont.end(); iter++) { sum += *iter; } return sum; } */ //Sum Generic Map //template template double Sum(const map& mp) { double sum = 0; typename map::const_iterator iter = mp.begin(); for (iter; iter != mp.end(); iter++) { sum += iter->second; } return sum; } template typename map::const_iterator test(const map&mp) { return(mp.begin()); } /* //Sum Generic Container Iterators template double Sum(T& begin, const T& end) { double sum = 0; for (begin; begin != end; begin++) { sum += *begin; } return sum; } //Sum Generic Map Iterators template double Sum(map::iterator& begin, map::iterator& end) { double sum = 0; for (begin; begin != end; begin++) { sum += begin->second; } return sum; } */ void add_To_Map(map *Map, deque queIn) { double x1 = *queIn.begin(); double f = *queIn.rbegin(); if ( Map->find(x1)!=Map->end() ) { stringstream ss; ss<<"HIT: Key x="<insert(pair(x1, f)); } template void add_To_Map (map *Map, deque queIn) { int dim = (int)queIn.size()-1; if (dim<1) { stringstream ss; ss<<"addTo_Map: vecIn not big enough."; cout<find(xN)==Map->end() ) { // No such element -> generate new Map and insert T tempMap; add_To_Map(&tempMap, queIn); Map->insert(pair(xN,tempMap)); } else { // Found such element -> Insert new pair add_To_Map(&Map->find(xN)->second, queIn); //Add element in element, using pointer to subMap. } } int main() { //Map cout << "map" << endl; map mp; /* mp[3] = 5.5; mp[4] = 6.7; mp[5] = 8.4; cout<first< queIn; map> d2mp; queIn.push_back(3); queIn.push_back(4); queIn.push_back(5); add_To_Map(&d2mp, queIn); queIn.pop_back(); queIn.pop_back(); queIn.push_back(6); queIn.push_back(7); add_To_Map(&d2mp, queIn); //cout << Sum(mp) <::iterator mp_iter_begin = mp.begin(); //map::iterator mp_iter_end = mp.end(); //cout << Sum(mp_iter_begin, mp_iter_end) << endl; return 0; }