Skip to content

stringbuilder example does not compile in C++20, serialize_tag should not require custom_deserializable<T> #2549

@pgrAm

Description

@pgrAm

So I was trying out the custom serialization is simdjson and I could not get the example to compile in C++20 with clang or msvc.

The issue turns out to be that in the definition for serialize_tag it is declared to require custom_deserializable<T>. This is a problem since it means you cannot create a type that is serializable without also writing a custom deserializer, and also because the type in the concept does not use std::remove_cv it means the constness would have to match in the serializer.

The code, based on the example provided here illustrates the issue https://github.com/simdjson/simdjson/blob/master/doc/builder.md#example--string-builder,
as it does not compile in C++20 mode in MSVC or clang

#include <string>
#include <vector>
#include <stdint.h>
#include <simdjson.h>

struct Car {
	std::string make;
	std::string model;
	int64_t year;
	std::vector<float> tire_pressure;
};

namespace simdjson {

	template <typename builder_type>
	void tag_invoke(serialize_tag, builder_type& builder, const Car& car) {
		builder.start_object();
		builder.append_key_value("make", car.make);
		builder.append_comma();
		builder.append_key_value("model", car.model);
		builder.append_comma();
		builder.append_key_value("year", car.year);
		builder.append_comma();
		builder.append_key_value("tire_pressure", car.tire_pressure);
		builder.end_object();
	}
} // namespace simdjson

int main()
{
	simdjson::builder::string_builder output_json;

	Car c = { "Toyota", "Corolla", 2017, {30.0,30.2,30.513,30.79} };

	output_json.append_key_value("car", c);
}

msvc gives call to object of class type 'simdjson::serialize_tag': no matching call operator found

and clang gives no matching function for call to object of type 'const struct serialize_tag'

I am using the 4.2.2 release version on windows acquired through vcpkg

I think the requires clause from serialize_tag should be removed or replaced with a new custom_serializable concept

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions