Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concepts to test for serializability #89

Open
hlewin opened this issue Apr 22, 2024 · 2 comments
Open

Concepts to test for serializability #89

hlewin opened this issue Apr 22, 2024 · 2 comments

Comments

@hlewin
Copy link
Contributor

hlewin commented Apr 22, 2024

Hello!

Would it be possible to define concepts that check if a type can be serialized (or reflected)?
I know there are static assertions in place already, but I would really like to have a way to do something like

static_assert( is_serializable<MyType> )
@liuzicheng1987
Copy link
Contributor

liuzicheng1987 commented Apr 22, 2024

@hlewin , there are currently no such static assertions.

I think it's certainly doable, but it might be slightly more tricky than you think. What you would want to do is to write a concept that checks whether parsing::Parser<R, W, MyType>::write(...) compiles. (And if you want to support is_deserializable<MyType> as well you could check whether parsing::Parser<R, W, MyType>::read(...) compiles.)

I am assuming that you want to do this independently of any particular serialization format. So that means you have to write your own "mock reader" and "mock writer" for this concept.

The concepts for the reader and writer are laid out in here:

https://github.com/getml/reflect-cpp/blob/main/include/rfl/parsing/IsReader.hpp

https://github.com/getml/reflect-cpp/blob/main/include/rfl/parsing/IsWriter.hpp

A PR is welcome.

@liuzicheng1987
Copy link
Contributor

@hlewin , in order to conform to C++ standards, I would suggest to add a _v as a suffix:

static_assert( is_serializable_v<MyType> )
static_assert( is_deserializable_v<MyType> )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants