Created
          September 11, 2012 03:27 
        
      - 
      
 - 
        
Save philtomson/3695736 to your computer and use it in GitHub Desktop.  
    some c++11 testing
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | //compile with: | |
| //g++ -std=c++11 -o test test.cpp | |
| #include <iostream> | |
| #include <map> | |
| #include <vector> | |
| typedef std::vector<std::string> StrVec; | |
| typedef std::map<std::string, StrVec > MapStr2Vec; | |
| MapStr2Vec mmap; | |
| template <class M, class K, class V> | |
| void add_to_map(M& m, | |
| const K& key, | |
| const V& str) { | |
| if( m.find(key) == m.end()) { | |
| StrVec v; | |
| v.push_back(str); | |
| m[key]=v; | |
| } else { | |
| (m[key]).push_back(str); | |
| } | |
| } | |
| int main(){ | |
| add_to_mmap<MapStr2Vec,std::string, std::string>(mmap,"foo","bar"); | |
| add_to_mmap<MapStr2Vec,std::string, std::string>(mmap,"foo","baz"); | |
| add_to_mmap<MapStr2Vec,std::string, std::string>(mmap,"kat","baz"); | |
| add_to_mmap<MapStr2Vec,std::string, std::string>(mmap,"kat","baz"); | |
| add_to_mmap<MapStr2Vec,std::string, std::string>(mmap,"kat","pow"); | |
| for(auto itr = mmap.begin(); itr != mmap.end(); ++itr){ | |
| std::cout << "Key: " << (*itr).first << std::endl; | |
| auto vec = (*itr).second; | |
| for( auto vi = vec.begin(); vi != vec.end(); ++vi){ | |
| std::cout << " Val: " << *vi << std::endl; | |
| } | |
| } | |
| return 0; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment