Created
November 6, 2011 21:31
-
-
Save dazfuller/1343524 to your computer and use it in GitHub Desktop.
Ignoring the Voices: C++11 Example - decltype
This file contains 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
#include <iostream> | |
#include <map> | |
#include <string> | |
#include <vector> | |
std::map<int, std::vector<std::string>> MyFunction() | |
{ | |
std::vector<std::string> v1; | |
v1.push_back("Hello"); | |
v1.push_back("World"); | |
std::vector<std::string> v2; | |
v2.push_back("Goodbye"); | |
v2.push_back("World"); | |
std::map<int, decltype(v2)> m1; | |
m1.insert(std::pair<int, decltype(v2)>(1, v1)); | |
m1.insert(std::pair<int, decltype(v2)>(2, v2)); | |
return m1; | |
} | |
auto MakeCollection() -> decltype( MyFunction() ) | |
{ | |
auto val = MyFunction(); | |
return val; | |
} | |
int main() | |
{ | |
auto collection = MakeCollection(); | |
for (auto m = collection.begin(); m != collection.end(); ++m) | |
{ | |
std::cout << m->first; | |
for (auto s = m->second.begin(); s != m->second.end(); ++s) | |
{ | |
std::cout << " " << *s; | |
} | |
std::cout << std::endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiled as follows:
g++ -std=c++0x -Wall -Werror -o decltype_useful decltype_useful.cpp