-
Notifications
You must be signed in to change notification settings - Fork 153
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
Generic supported concepts #1622
Conversation
@arturbac, This is a breaking change that will effect simple_enum. I intend to release this in v5.0.0. Do you have additional thoughts on this change? |
I looked at it, I was using those concepts and I will remove them from simple_enum header and move use to unit tests. #ifndef glz_feature_xxxx
static_assert(glz::read_json_supported<test_enum_e>);
static_assert(glz::write_json_supported<test_enum_e>);
#else
static_assert(glz::read_supported<glz::JSON,test_enum_e>);
static_assert(glz::write_supported<glz::JSON,test_enum_e>);
#endif |
My taughts: namespace glz::detail
{
template<simple_enum::bounded_enum enumeration_type>
#ifdef glaze_v3_5_0_to_from
struct from<glz::JSON, enumeration_type>
#else
struct from_json<enumeration_type>
#endif
{
template<auto Opts, typename... Args>
requires simple_enum::bounded_enum<enumeration_type>
static void op(enumeration_type & arg, is_context auto && ctx, Args &&... args)
{
std::string_view value;
#ifdef glaze_v3_5_0_to_from
read<glz::JSON>::op<Opts>(value, ctx, args...);
#else
read<glz::json>::op<Opts>(value, ctx, args...);
#endif
if(bool(ctx.error)) [[unlikely]]
return;
simple_enum::expected<enumeration_type, simple_enum::enum_cast_error> res{simple_enum::enum_cast<enumeration_type>(value
)};
if(!res.has_value()) [[unlikely]]
{
ctx.error = error_code::syntax_error;
return;
}
arg = res.value();
}
}; So actually when You plan to remove detail all I have to do is to remove namespace scope and use namespace prefix dependant on feature test macro #ifdef glz_feature_xxx....
namespace glz_spec_namespace = glz::detail;
#else
namespace glz_spec_namespace = glz;
#endif
template<simple_enum::bounded_enum enumeration_type>
#ifdef glaze_v3_5_0_to_from
struct glz_spec_namespace::from<glz::JSON, enumeration_type>
#else
struct glz_spec_namespace::from_json<enumeration_type>
#endif
{ |
Give me names of feature test macros and I'll blind implement those changes, for You in advance. |
@arturbac, Sweet! The feature test macro |
The format specific concepts like:
read_json_supported
andwrite_beve_supported
added extra boilerplate and did not allow custom formats. This change removes these non-generic functions and simply uses:This more generic solution simplifies the code and makes adding new formats cleaner and possible for users without needing to modify the main Glaze repository.
Requested in #1619, but also noticed when beginning to add TOML that this approach is bad, especially as the number of formats grows.