Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Proxy/Wrappers for mulitple defines #34

@Sven-vh

Description

@Sven-vh

Hi, I want to define different members for specific use cases.
For example:

template<typename T>
struct _SerializeProxy { T& self; };

struct Transform {
private:
	BEFRIEND_VISITABLE();
	glm::vec3 m_position;
	glm::vec3 m_scale;
	glm::quat m_rotation;
};

// Default, all values
VISITABLE_STRUCT(Transform, m_position, m_scale, m_rotation);

// Define only the values for serialization, so only pos and scale
VISITABLE_STRUCT(_SerializeProxy<Transform>, m_position, m_scale);

In this example, I thought of using a proxy so I could differentiate when I want all of the member variables or only the seiraliza ones. Sadly this doesn't work since:

1>E:\GithubProjects\svh\include\components\transform.hpp(27,1): error C2039: 'm_position': is not a member of '_SerializeProxy<Transform>'
1>E:\GithubProjects\svh\include\components\transform.hpp(27,1): message : see declaration of '_SerializeProxy<Transform>'
1>E:\GithubProjects\svh\include\components\transform.hpp(27,1): error C2065: 'm_position': undeclared identifier
1>E:\GithubProjects\svh\include\components\transform.hpp(27,1): error C2039: 'm_scale': is not a member of '_SerializeProxy<Transform>'
1>E:\GithubProjects\svh\include\components\transform.hpp(27,1): message : see declaration of '_SerializeProxy<Transform>'
1>E:\GithubProjects\svh\include\components\transform.hpp(27,1): error C2065: 'm_scale': undeclared identifier
1>E:\GithubProjects\svh\include\components\transform.hpp(27,1): error C3615: constexpr function 'visit_struct::traits::visitable<_SerializeProxy<Transform>,void>::get_pointer' cannot result in a constant expression
1>E:\GithubProjects\svh\include\components\transform.hpp(27,1): message : failure was because type 'unknown-type' is not a literal type
1>E:\GithubProjects\svh\include\components\transform.hpp(27): message : failure was caused by control reaching the end of a constexpr function
1>E:\GithubProjects\svh\include\components\transform.hpp(27,1): error C3615: constexpr function 'visit_struct::traits::visitable<_SerializeProxy<Transform>,void>::get_accessor' cannot result in a constant expression
1>E:\GithubProjects\svh\include\components\transform.hpp(27,1): message : failure was because type 'unknown-type' is not a literal type
1>E:\GithubProjects\svh\include\components\transform.hpp(27): message : failure was caused by control reaching the end of a constexpr function
1>Done building project "svh.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 23:57 and took 00,484 seconds ==========

I tried defining it like this:

VISITABLE_STRUCT(_SerializeProxy<Transform>, self.m_position, self.m_scale);

But that doesn't work either.

Which all makes sense, but is there a way to achieve something like this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions