I was wondering if there is any equivalent, or a way to fake, C# style anonymous types in C++. I'm using gcc 4.6 so any parts of C++0x it supports can be used.
+3
A:
If you’re looking for a container that can hold a “bag” of different types, the closest analog would be std::tuple. (Microsoft documentation, but also applies to gcc.)
Nate
2010-10-22 16:02:35
+1 for another elegant solution.
Billy ONeal
2010-10-22 16:07:01
+1
A:
You can sort of fake it with a std::map<std::string, boost::any>, but that's really not the same. There's no way to get anything truly like C# 3+'s anonymous types in C++.
Anonymous types are really only useful for LINQ anyway, and C++ doesn't support anything like that either, so it's unlikely that such would be useful anyway.
Billy ONeal
2010-10-22 16:05:35