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

Custom Wrappers Example Fails: ‘json’ Was Not Declared in This Scope #1637

Open
hs-vc opened this issue Mar 4, 2025 · 0 comments
Open

Comments

@hs-vc
Copy link

hs-vc commented Mar 4, 2025

I was following the example in custom-wrappers.md, but when I tried to compile the code, I got the following error:

error: ‘json’ was not declared in this scope; did you mean ‘glz::fast_float::chars_format::json’?
   19 |             read<json>::op<Opts>(value.val, args...);
      |                  ^~~~
      |                  glz::fast_float::chars_format::json

I am unsure if I am missing an necessary header or if the documentation needs to be updated to reflect a namespace change in the newer version of Glaze.

Additionally, when I try to compile the following code with Glaze v 4.4.3, which worked in Glaze v4.3.1

#include <glaze/glaze.hpp>
#include <iostream>

template<class T>
struct my_quoted_t {
    T val;
};

namespace glz::detail {
    template<class T>
    struct from<JSON, my_quoted_t<T>> {
        template<auto Opts>
        static void op(auto &&value, auto &&... args) {
            skip_ws<Opts>(args...);
            match<'"'>(args...);
            read<JSON>::op<Opts>(value.val, args...);
            match<'"'>(args...);
        }
    };

    template<class T>
    struct to<JSON, my_quoted_t<T>> {
        template<auto Opts>
        static void op(auto &&value, is_context auto &&ctx, auto &&... args) noexcept {
            dump<'"'>(args...);
            write<JSON>::op<Opts>(value.val, ctx, args...);
            dump<'"'>(args...);
        }
    };
}

struct A {
   my_quoted_t<long> x;
};

int main() {
    std::string m = R"({"x":"100"})";
    A a{};
    auto e = glz::read<glz::opts{
        .error_on_unknown_keys = false,
        .error_on_missing_keys = true
    }>(a, m);

    if (e) {
        std::cerr << glz::format_error(e) << std::endl;
    } else {
        std::cout << a.x.val << std::endl;
    }

    return 0;
}

I get the following errors:

main.cpp:16:23: error: no matching function for call to ‘match<'\"'>(glz::context&, const char*&, const char*&)’
   16 |             match<'"'>(args...);
      |                  ^~~~

Could you let me know how to fix this?

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

1 participant