Pythonistas, get your hands off from C++!!!
Hehe it doesn't hurt performance the way python does I promise!
You might be interested in my project Aurora, especially the Tuple metaprogramming file and the Named Tuple macros
Your Aurora NamedTuple looks pretty cool. If you can iterate over those members (even if it's at compile time with recursive templates), then that's exactly what I want. Is that possible?
I just threw this together for fun, I don't really think it's usable yet, but maybe it could be prettied up with some macros
Also, without the compiler optimizations, the low performance scares me.
Here's some classes:
struct Foo
{
std::string str;
int i;
};
std::ostream& operator<<(std::ostream& left, const Foo& right)
{
return left << "str: " << right.str << ", " << "i: " << right.i;
}
struct Test : public Reflectable<struct name, std::string,
struct health, int,
struct foo, Foo>
{
};
And a little sample processor to iterate through members:
class SamplePrinter
{
public:
/// \brief Int serialization
void operator () (int x)
{
std::cout << "int: " << x << std::endl;
}
/// \brief Float serialization
void operator () (float x)
{
std::cout << "float: " << x << std::endl;
}
/// \brief Double serialization
void operator () (double x)
{
std::cout << "double: " << x << std::endl;
}
/// \brief String serialization
void operator () (const std::string& x)
{
std::cout << "string: " << x << std::endl;
}
/// \brief The generic case
template <typename X>
void operator () (const X& x)
{
std::cout << "other: " << x << std::endl;
}
private:
};
And Using the stuff
Test test;
test.get<name>() = "bob";
test.get<health>() = 42;
test.get<foo>().str = "hello";
test.get<foo>().i = 24;
test.iterate(SamplePrinter());
I'm also pondering how you could make a macro to automatically set up references to the tuple members as public member variables, allowing you to access the variables with regular syntax. The benchmark shows that reference access is a little slower than regular tuple access with compiler optimizations on, though.