I'm trying to implement a "property" system to convert C++ instances into JSON and vice versa. I took a part of the code from Guillaume Racicot's answer in this question (C++ JSON Serialization) and simplified it.
Here is how I proceed. I have a Property
class:
template <typename Class, typename T>
struct Property {
constexpr Property(T Class::* member, const char* name) : m_member(member), m_name(name) {}
T Class::* m_member;
const char* m_name;
};
m_member points to a specific member of Class
Let's say I want to define properties for a User
class, I would like to be able to proceed like this, to be able to assign members a property name:
class User
{
public:
int age;
constexpr static auto properties = std::make_tuple(
Property<User, int>(&User::age, "age")
);
}
This code compiles and works correctly in GCC(http://coliru.stacked-crooked.com/a/276ac099068579fd) but not in Visual Studio 2015 Update 3. I get those errors:
main.cpp(19) : error C2327 : 'User::age' : is not a type name, static, or enumerator
main.cpp(19) : error C2065 : 'age' : undeclared identifier
main.cpp(20) : error C2672 : 'std::make_tuple' : no matching overloaded function found
main.cpp(20) : error C2119 : 'properties' : the type for 'auto' cannot be deduced from an empty initializer
Would there be a workaround to make it work in Visual Studio 2015 Update 3?