Giter VIP home page Giter VIP logo

glaze's Introduction

Glaze

One of the fastest JSON libraries in the world. Glaze reads and writes from object memory, simplifying interfaces and offering incredible performance.

Glaze also supports:

  • BEVE (binary efficient versatile encoding)
  • CSV (comma separated value)

With compile time reflection for MSVC, Clang, and GCC!

Highlights

  • Pure, compile time reflection for structs

  • Standard C++ library support

  • Header only

  • Direct to memory serialization/deserialization

  • Compile time maps with constant time lookups and perfect hashing

  • Nearly zero intermediate allocations

  • Powerful wrappers to modify read/write behavior (Wrappers)

  • Use your own custom read/write functions (Custom Read/Write)

  • Handle unknown keys in a fast and flexible manner

  • Direct memory access through JSON pointer syntax

  • Binary data through the same API for maximum performance

  • No exceptions (compiles with -fno-exceptions)

  • No runtime type information necessary (compiles with -fno-rtti)

  • Rapid error handling with short circuiting

  • JSON-RPC 2.0 support

  • JSON Schema generation

  • CSV Reading/Writing

  • Much more!

See DOCS for more documentation.

Performance

Library Roundtrip Time (s) Write (MB/s) Read (MB/s)
Glaze 1.20 1078 1081
simdjson (on demand) N/A N/A 1198
yyjson 1.22 1007 1109
daw_json_link 2.88 366 560
RapidJSON 3.70 289 441
Boost.JSON (direct) 4.78 198 441
json_struct 5.49 178 336
nlohmann 15.56 84 82

Performance test code available here

Performance caveats: simdjson and yyjson are great, but they experience major performance losses when the data is not in the expected sequence or any keys are missing (the problem grows as the file size increases, as they must re-iterate through the document).

Also, simdjson and yyjson do not support automatic escaped string handling, so if any of the currently non-escaped strings in this benchmark were to contain an escape, the escapes would not be handled.

ABC Test shows how simdjson has poor performance when keys are not in the expected sequence:

Library Read (MB/s)
Glaze 988
simdjson (on demand) 110

Binary Performance

Tagged binary specification: BEVE

Metric Roundtrip Time (s) Write (MB/s) Read (MB/s)
Raw performance 0.44 3168 2350
Equivalent JSON data* 0.44 3474 2577

JSON size: 670 bytes

BEVE size: 611 bytes

*BEVE packs more efficiently than JSON, so transporting the same data is even faster.

Example

Your struct will automatically get reflected! No metadata is required by the user.

struct my_struct
{
  int i = 287;
  double d = 3.14;
  std::string hello = "Hello World";
  std::array<uint64_t, 3> arr = { 1, 2, 3 };
  std::map<std::string, int> map{{"one", 1}, {"two", 2}};
};

JSON (prettified)

{
   "i": 287,
   "d": 3.14,
   "hello": "Hello World",
   "arr": [
      1,
      2,
      3
   ],
   "map": {
      "one": 1,
      "two": 2
   }
}

Write JSON

my_struct s{};
std::string buffer = glz::write_json(s);

or

my_struct s{};
std::string buffer{};
glz::write_json(s, buffer);

Read JSON

std::string buffer = R"({"i":287,"d":3.14,"hello":"Hello World","arr":[1,2,3],"map":{"one":1,"two":2}})";
auto s = glz::read_json<my_struct>(buffer);
if (s) // check std::expected
{
  s.value(); // s.value() is a my_struct populated from buffer
}

or

std::string buffer = R"({"i":287,"d":3.14,"hello":"Hello World","arr":[1,2,3],"map":{"one":1,"two":2}})";
my_struct s{};
auto ec = glz::read_json(s, buffer); // populates s from buffer
if (ec) {
  // handle error
}

Read/Write From File

auto ec = glz::read_file_json(obj, "./obj.json", std::string{});
auto ec = glz::write_file_json(obj, "./obj.json", std::string{});

Compiler/System Support

  • Requires C++20
  • Only designed and tested for 64bit little-endian systems

Actions build and test with Clang (15+), MSVC (2022), and GCC (11+) on apple, windows, and linux.

clang build gcc build msvc build

How To Use Glaze

include(FetchContent)

FetchContent_Declare(
  glaze
  GIT_REPOSITORY https://github.com/stephenberry/glaze.git
  GIT_TAG main
  GIT_SHALLOW TRUE
)

FetchContent_MakeAvailable(glaze)

target_link_libraries(${PROJECT_NAME} PRIVATE glaze::glaze)
find_package(glaze REQUIRED)

target_link_libraries(main PRIVATE glaze::glaze)

Arch Linux

See this Example Repository for how to use Glaze in a new project


See FAQ for Frequently Asked Questions

Explicit Metadata

If you want to specialize your reflection then you can optionally write the code below:

This metadata is also necessary for non-aggregate initializable structs.

template <>
struct glz::meta<my_struct> {
   using T = my_struct;
   static constexpr auto value = object(
      &T::i,
      &T::d,
      &T::hello,
      &T::arr,
      &T::map
   );
};

Local Glaze Meta

Glaze also supports metadata provided within its associated class:

struct my_struct
{
  int i = 287;
  double d = 3.14;
  std::string hello = "Hello World";
  std::array<uint64_t, 3> arr = { 1, 2, 3 };
  std::map<std::string, int> map{{"one", 1}, {"two", 2}};
  
  struct glaze {
     using T = my_struct;
     static constexpr auto value = glz::object(
        &T::i,
        &T::d,
        &T::hello,
        &T::arr,
        &T::map
     );
  };
};

Custom Key Names or Unnamed Types

When you define Glaze metadata, objects will automatically reflect the names of your member object pointers. However, if you want custom names or you register lambda functions or wrappers that do not provide names for your fields, you can optionally add field names in your metadata.

Example of custom names:

template <>
struct glz::meta<my_struct> {
   using T = my_struct;
   static constexpr auto value = object(
      "integer", &T::i,
      "double", &T::d,
      "string", &T::hello,
      "array", &T::arr,
      "my map", &T::map
   );
};

Each of these strings is optional and can be removed for individual fields if you want the name to be reflected.

Names are required for:

  • Wrappers
  • Lambda functions

Custom Read/Write

Custom reading and writing can be achieved through the powerful to_json/from_json specialization approach, which is described here: custom-serialization.md. However, this only works for user defined types.

For common use cases or cases where a specific member variable should have special reading and writing, you can use glz::custom to register read/write member functions, std::functions, or lambda functions.

See an example:

struct custom_encoding
{
   uint64_t x{};
   std::string y{};
   std::array<uint32_t, 3> z{};
   
   void read_x(const std::string& s) {
      x = std::stoi(s);
   }
   
   uint64_t write_x() {
      return x;
   }
   
   void read_y(const std::string& s) {
      y = "hello" + s;
   }
   
   auto& write_z() {
      z[0] = 5;
      return z;
   }
};

template <>
struct glz::meta<custom_encoding>
{
   using T = custom_encoding;
   static constexpr auto value = object("x", custom<&T::read_x, &T::write_x>, //
                                        "y", custom<&T::read_y, &T::y>, //
                                        "z", custom<&T::z, &T::write_z>);
};

suite custom_encoding_test = [] {
   "custom_reading"_test = [] {
      custom_encoding obj{};
      std::string s = R"({"x":"3","y":"world","z":[1,2,3]})";
      expect(!glz::read_json(obj, s));
      expect(obj.x == 3);
      expect(obj.y == "helloworld");
      expect(obj.z == std::array<uint32_t, 3>{1, 2, 3});
   };
   
   "custom_writing"_test = [] {
      custom_encoding obj{};
      std::string s = R"({"x":"3","y":"world","z":[1,2,3]})";
      expect(!glz::read_json(obj, s));
      std::string out{};
      glz::write_json(obj, out);
      expect(out == R"({"x":3,"y":"helloworld","z":[5,2,3]})");
   };
};

Object Mapping

When using member pointers (e.g. &T::a) the C++ class structures must match the JSON interface. It may be desirable to map C++ classes with differing layouts to the same object interface. This is accomplished through registering lambda functions instead of member pointers.

template <>
struct glz::meta<Thing> {
   static constexpr auto value = object(
      "i", [](auto&& self) -> auto& { return self.subclass.i; }
   );
};

The value self passed to the lambda function will be a Thing object, and the lambda function allows us to make the subclass invisible to the object interface.

Lambda functions by default copy returns, therefore the auto& return type is typically required in order for glaze to write to memory.

Note that remapping can also be achieved through pointers/references, as glaze treats values, pointers, and references in the same manner when writing/reading.

Value Types

A class can be treated as an underlying value as follows:

struct S {
  int x{};
};

template <>
struct glz::meta<S> {
  static constexpr auto value{ &S::x };
};

or using a lambda:

template <>
struct glz::meta<S> {
  static constexpr auto value = [](auto& self) -> auto& { return self.x; };
};

Error Handling

Glaze is safe to use with untrusted messages. Errors are returned as error codes, typically within a glz::expected, which behaves just like a std::expected.

Glaze works to short circuit error handling, which means the parsing exits very rapidly if an error is encountered.

To generate more helpful error messages, call format_error:

auto pe = glz::read_json(obj, buffer);
if (pe) {
  std::string descriptive_error = glz::format_error(pe, s);
}

This test case:

{"Hello":"World"x, "color": "red"}

Produces this error:

1:17: syntax_error
   {"Hello":"World"x, "color": "red"}
                   ^

Denoting that x is invalid here.

Type Support

Array Types

Array types logically convert to JSON array values. Concepts are used to allow various containers and even user containers if they match standard library interfaces.

  • glz::array (compile time mixed types)
  • std::tuple
  • std::array
  • std::vector
  • std::deque
  • std::list
  • std::forward_list
  • std::span
  • std::set
  • std::unordered_set

Object Types

Object types logically convert to JSON object values, such as maps. Like JSON, Glaze treats object definitions as unordered maps. Therefore the order of an object layout does not have to match the same binary sequence in C++.

  • glz::object (compile time mixed types)
  • std::map
  • std::unordered_map

Variants

  • std::variant

See Variant Handling for more information.

Nullable Types

  • std::unique_ptr
  • std::shared_ptr
  • std::optional

Nullable types may be allocated by valid input or nullified by the null keyword.

std::unique_ptr<int> ptr{};
std::string buffer{};
glz::write_json(ptr, buffer);
expect(buffer == "null");

glz::read_json(ptr, "5");
expect(*ptr == 5);
buffer.clear();
glz::write_json(ptr, buffer);
expect(buffer == "5");

glz::read_json(ptr, "null");
expect(!bool(ptr));

Enums

By default enums will be written and read in integer form. No glz::meta is necessary if this is the desired behavior.

However, if you prefer to use enums as strings in JSON, they can be registered in the glz::meta as follows:

enum class Color { Red, Green, Blue };

template <>
struct glz::meta<Color> {
   using enum Color;
   static constexpr auto value = enumerate(Red,
                                           Green,
                                           Blue
   );
};

In use:

Color color = Color::Red;
std::string buffer{};
glz::write_json(color, buffer);
expect(buffer == "\"Red\"");

JSON With Comments (JSONC)

Comments are supported with the specification defined here: JSONC

Comments may also be included in the glz::meta description for your types. These comments can be written out to provide a description of your JSON interface. Calling write_jsonc as opposed to write_json will write out any comments included in the meta description.

struct thing {
  double x{5.0};
  int y{7};
};

template <>
struct glz::meta<thing> {
   using T = thing;
   static constexpr auto value = object(
      &T::x, "x is a double"_c,
      &T::y, "y is an int"_c
   );
};

Prettified output:

{
  "x": 5 /*x is a double*/,
  "y": 7 /*y is an int*/
}

The _c is necessary if member object pointer names are reflected. You can also write comment("x is a double")

Prettify JSON

Formatted JSON can be written out directly via a compile time option:

glz::write<glz::opts{.prettify = true}>(obj, buffer);

Or, JSON text can be formatted with the glz::prettify_json function:

std::string buffer = R"({"i":287,"d":3.14,"hello":"Hello World","arr":[1,2,3]})");
auto beautiful = glz::prettify_json(buffer);

beautiful is now:

{
   "i": 287,
   "d": 3.14,
   "hello": "Hello World",
   "arr": [
      1,
      2,
      3
   ]
}

Minify JSON

To minify JSON:

glz::write<glz::opts{.prettify = true}>(obj, buffer);
std::string minified = glz::minify_json(buffer);

Boolean Flags

Glaze supports registering a set of boolean flags that behave as an array of string options:

struct flags_t {
   bool x{ true };
   bool y{};
   bool z{ true };
};

template <>
struct glz::meta<flags_t> {
   using T = flags_t;
   static constexpr auto value = flags("x", &T::x, "y", &T::y, "z", &T::z);
};

Example:

flags_t s{};
expect(glz::write_json(s) == R"(["x","z"])");

Only "x" and "z" are written out, because they are true. Reading in the buffer will set the appropriate booleans.

When writing BEVE, flags only use one bit per boolean (byte aligned).

Logging JSON

Sometimes you just want to write out JSON structures on the fly as efficiently as possible. Glaze provides tuple-like structures that allow you to stack allocate structures to write out JSON with high speed. These structures are named glz::obj for objects and glz::arr for arrays.

Below is an example of building an object, which also contains an array, and writing it out.

auto obj = glz::obj{"pi", 3.14, "happy", true, "name", "Stephen", "arr", glz::arr{"Hello", "World", 2}};

std::string s{};
glz::write_json(obj, s);
expect(s == R"({"pi":3.14,"happy":true,"name":"Stephen","arr":["Hello","World",2]})");

This approach is significantly faster than glz::json_t for generic JSON. But, may not be suitable for all contexts.

Merge

glz::merge allows the user to merge multiple JSON object types into a single object.

glz::obj o{"pi", 3.141};
std::map<std::string_view, int> map = {{"a", 1}, {"b", 2}, {"c", 3}};
auto merged = glz::merge{o, map};
std::string s{};
glz::write_json(merged, s); // will write out a single, merged object
// s is now: {"pi":3.141,"a":0,"b":2,"c":3}

glz::merge stores references to lvalues to avoid copies

Generic JSON

See Generic JSON for glz::json_t.

glz::json_t json{};
std::string buffer = R"([5,"Hello World",{"pi":3.14}])";
glz::read_json(json, buffer);
assert(json[2]["pi"].get<double>() == 3.14);

Raw Buffer Performance

Glaze is just about as fast writing to a std::string as it is writing to a raw char buffer. If you have sufficiently allocated space in your buffer you can write to the raw buffer, as shown below, but it is not recommended.

glz::read_json(obj, buffer);
const auto n = glz::write_json(obj, buffer.data());
buffer.resize(n);

Compile Time Options

The glz::opts struct defines compile time optional settings for reading/writing.

Instead of calling glz::read_json(...), you can call glz::read<glz::opts{}>(...) and customize the options.

For example: glz::read<glz::opts{.error_on_unknown_keys = false}>(...) will turn off erroring on unknown keys and simple skip the items.

glz::opts can also switch between formats:

  • glz::read<glz::opts{.format = glz::binary}>(...) -> glz::read_binary(...)
  • glz::read<glz::opts{.format = glz::json}>(...) -> glz::read_json(...)

Available Compile Time Options

The struct below shows the available options and the default behavior.

struct opts {
  uint32_t format = json;
  bool comments = false; // Write out comments
  bool error_on_unknown_keys = true; // Error when an unknown key is encountered
  bool skip_null_members = true; // Skip writing out params in an object if the value is null
  bool use_hash_comparison = true; // Will replace some string equality checks with hash checks
  bool prettify = false; // Write out prettified JSON
  char indentation_char = ' '; // Prettified JSON indentation char
  uint8_t indentation_width = 3; // Prettified JSON indentation size
  bool shrink_to_fit = false; // Shrinks dynamic containers to new size to save memory
  bool write_type_info = true; // Write type info for meta objects in variants
  bool force_conformance = false; // Do not allow invalid json normally accepted such as comments, nan, inf.
  bool error_on_missing_keys = false; // Require all non nullable keys to be present in the object. Use
                                      // skip_null_members = false to require nullable members
  bool error_on_const_read = false; // Error if attempt is made to read into a const value, by 
                                    // default the value is skipped without error
  uint32_t layout = rowwise; // CSV row wise output/input
  bool quoted_num = false; // treat numbers as quoted or array-like types as having quoted numbers
  bool number = false; // read numbers as strings and write these string as numbers
  bool raw = false; // write out string like values without quotes
  bool raw_string = false; // do not decode/encode escaped characters for strings (improves read/write performance)
};

Many of these compile time options have wrappers to apply the option to only a single field. See Wrappers for more details.

Skip

It can be useful to acknowledge a keys existence in an object to prevent errors, and yet the value may not be needed or exist in C++. These cases are handled by registering a glz::skip type with the meta data.

struct S {
  int i{};
};

template <>
struct glz::meta<S> {
  static constexpr auto value = object("key_to_skip", skip{}, &S::i);
};
std::string buffer = R"({"key_to_skip": [1,2,3], "i": 7})";
S s{};
glz::read_json(s, buffer);
// The value [1,2,3] will be skipped
expect(s.i == 7); // only the value i will be read into

Hide

Glaze is designed to help with building generic APIs. Sometimes a value needs to be exposed to the API, but it is not desirable to read in or write out the value in JSON. This is the use case for glz::hide.

glz::hide hides the value from JSON output while still allowing API (and JSON pointer) access.

struct hide_struct {
  int i = 287;
  double d = 3.14;
  std::string hello = "Hello World";
};

template <>
struct glz::meta<hide_struct> {
   using T = hide_struct;
   static constexpr auto value = object(&T::i,  //
                                        &T::d, //
                                        "hello", hide{&T::hello});
};
hide_struct s{};
auto b = glz::write_json(s);
expect(b == R"({"i":287,"d":3.14})"); // notice that "hello" is hidden from the output

Quoted Numbers

You can parse quoted JSON numbers directly to types like double, int, etc. by utilizing the glz::quoted wrapper.

struct A {
   double x;
   std::vector<uint32_t> y;
};

template <>
struct glz::meta<A> {
   static constexpr auto value = object("x", glz::quoted_num<&A::x>, "y", glz::quoted_num<&A::y>;
};
{
  "x": "3.14",
  "y": ["1", "2", "3"]
}

The quoted JSON numbers will be parsed directly into the double and std::vector<uint32_t>. The glz::quoted function works for nested objects and arrays as well.

NDJSON Support

Glaze supports Newline Delimited JSON for array-like types (e.g. std::vector and std::tuple).

std::vector<std::string> x = { "Hello", "World", "Ice", "Cream" };
std::string s = glz::write_ndjson(x);
glz::read_ndjson(x, s);

More Features

  • Output performance profiles to JSON and visualize using Perfetto

Extensions

See the ext directory for extensions.

License

Glaze is distributed under the MIT license with an exception for embedded forms:

--- Optional exception to the license ---

As an exception, if, as a result of your compiling your source code, portions of this Software are embedded into a machine-executable object form of such source code, you may redistribute such embedded portions in such object form without including the copyright and permission notices.

glaze's People

Contributors

arturbac avatar axojhf avatar bowdown097 avatar clyraz avatar dabader avatar friendlyanon avatar gunderwood4 avatar haatschii avatar helmesjo avatar huangminghuang avatar isaki avatar jason5480 avatar jbbjarnason avatar justend29 avatar katazina0 avatar lamweilun avatar maor-da avatar matrixberry avatar mwalcott3 avatar omarhogni avatar pwqbot avatar rozefound avatar slaaneshchosen avatar spongman avatar stephenberry avatar taita2104 avatar theluckycoder avatar toge avatar vlotoshko avatar wolfleader101 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

glaze's Issues

Extra glaze directory when installing, some unused files are being installed?

When doing make install after building, the include directory is buried inside two glaze's, the other one feels unnecessary:

$ cmake --install-prefix=/usr/local ..
...
$ make
...
$ make install
...
-- Installing: /usr/local/include/glaze/glaze/util/bit.hpp
...

Would prefer seeing:

-- Installing: /usr/local/include/glaze/util/bit.hpp

Also some files are installed even if they don't seem to be used:

...
-- Installing: /usr/local/lib/cmake/ut-1.1.9/utTargets.cmake
-- Installing: /usr/local/lib/cmake/ut-1.1.9/utConfigVersion.cmake
-- Installing: /usr/local/lib/cmake/ut-1.1.9/utConfig.cmake
-- Installing: /usr/local/include/ut-1.1.9/include
-- Installing: /usr/local/include/ut-1.1.9/include/boost
-- Installing: /usr/local/include/ut-1.1.9/include/boost/ut.hpp
$ grep -r ut.hpp /usr/local/include/glaze | wc
      0       0       0
$ grep -r ut.hpp /usr/local/share/glaze | wc
      0       0       0
$

If they are needed, it's a bit weird that the cmake files are placed in different directory structure than glaze's own, PREFIX/lib/cmake/... vs PREFIX/share/...:

-- Installing: /usr/local/share/glaze/glazeConfig.cmake
-- Installing: /usr/local/share/glaze/glazeConfigVersion.cmake
-- Installing: /usr/local/share/glaze/glazeTargets.cmake

Remove frozen as dependency

We already use our own constexpr perfect hasmap when keys are bellow 20. We just need to add a space efficient implementation that can be used for larger numbers of keys.

Fails to build on GCC 10, 11, and 12, "the address of ‘glz::opts{10, false}’ is not a valid template argument"

include/glaze/core/write.hpp:24:58: error: the address of ‘glz::opts{10, false}’ is not a valid template argument
24 | detail::write<Opts.format>::template op(std::forward(value), buffer, ix);

With basic test program:

#include <glaze/json/write.hpp>

#include <iostream>
#include <string>

struct my_struct {
  int i = 287;
  double d = 3.14;
  std::string hello = "Hello World";
  std::array<uint64_t, 3> arr = {1, 2, 3};
};

template <> struct glz::meta<my_struct> {
  using T = my_struct;
  static constexpr auto value = object("i", &T::i,         //
                                       "d", &T::d,         //
                                       "hello", &T::hello, //
                                       "arr", &T::arr      //
  );
};

int main() {
  my_struct s;
  std::string buffer;
  glz::write_json(s, buffer);
  std::cout << buffer << '\n';
}

Support round-tripping 64-bit ints

Description

Support round-tripping 64-bit ints. Consider the following struct:

struct Value {
    long long value;
};
template <>
struct glz::meta<Value> {
    using T = Value;
    constexpr static auto value = object(
        "value", &Value::value
    );
};

My general expectation is that, provided v doesn't contain any floating point numbers, the following holds:

glz::read_json<Value>(glz::write_json(v)) == v

However, it seems as though numbers are always parsed as floats, even if the corresponding field expects an int.

Consider the following example:

int main() {
    Value v1 { 32948729483739289 };

    std::string json = glz::write_json(v1);

    Value v2 = glz::read_json<Value>(json);

    printf("Json: %s\n", glz::prettify(json).c_str());

    if (v1.value != v2.value) {
        printf("Values not equal. v1 = %lli, v2 = %lli\n", v1.value, v2.value);
        return 1;
    } else {
        puts("All good!");
        return 0;
    }
}

This value is serialized properly (all digits intact), but when it's parsed, it's parsed as a float, then converted to an int.

This is the output of the above:

Json: {
   "value": 32948729483739289
}
Values not equal. v1 = 32948729483739289, v2 = 32948729483739288

Would it be possible to parse numbers as integers if the corresponding field calls for it?

How to read portion object from unknow JSON string?

Hi

I am reading through the README, however, I do not find an official way to read portion object from JSON string. The JSON pointer syntax dose not read a key from a unknow JSON message.

The common use case is to implement a API, we need to decide the message type, and then deserialize, for example

{
    "action": "PUT",
    "data": {
        "x": 100,
        "y": 200
    }
}

Expected way

std::string action = glz::read_json_whatever<std::string>("/path/to/action",  buffer);
if (action == "DELETE") {
    // Now we know the message type
    auto bomb = glz::read_json<bomb_t>(buffer);
}

Workaround (simdjson)

Using the simdjson on-demand API, I hope glaze can also have this.

#include <iostream>
#include "simdjson.h"

using namespace simdjson;

int main(void) {
    ondemand::parser parser;
    std::string_view action;

    std::string buffer = R"( { "action": "GET", "data": { "x": 10, "y": 200 }})";
    auto json = padded_string(buffer);
    auto request = parser.iterate(json);
    auto error = request.at_pointer("/action").get_string().get(action);

    if (action == "GET") {
        printf("TODO: deserialize with glaze as GET\n");
    }

    return 0;
}

Add option to allow parsing NaN as double

I realise it is disallowed by the JSON spec, but I have a data source I do not control who send down NaNs in double fields sometimes.

Would it be possible to add a glz::opt that would parse "NaN" as std::numeric_limits<double>::quiet_NaN?

Shorthand Way to Serialize/Deserialize Json To/From Struct?

Hi! I wanted to know if glaze has some shorthand way to serialize/deserialize a json to/from struct, like the one nlohmann json provides with NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE and NLOHMANN_DEFINE_TYPE_INTRUSIVE macros. To quote their solution,
image

If not yet, are there any plans to implement a similar or better thing? Since otherwise basic serialization/deserialization of deeply nested structs become a big pain.

Failed to build on VS 2022 17.0.2 - 'expression did not evaluate to a constant' . in write.hpp

Code failed to build using VS 2022. Error is 'expression did not evaluate to a constant' . in write.hpp. Line 232.

               static constexpr auto member_ptr =
                  std::get<member_it->second.index()>(member_it->second);

[{
"resource": "/C:/Users/akmal/projects/cpp/glaze/include/glaze/binary/write.hpp",
"owner": "cmake-build-diags",
"code": "C2131",
"severity": 8,
"message": "expression did not evaluate to a constant [C:\Users\akmal\projects\cpp\glaze\build\_glaze.vcxproj]",
"source": "MSVC",
"startLineNumber": 232,
"startColumn": 49,
"endLineNumber": 232,
"endColumn": 49
}]

json_ptr.hpp:514:102: internal compiler error: Segmentation fault

Building with GCC 10.3 (-std=c++20) on Ubuntu 20.04 and cmake 3.22.0 I get the following issue during build:

/home/developer/workspace/test/glaze/release/_deps/glaze-src/include/glaze/json/json_ptr.hpp: In function ‘constexpr bool glz::valid()’:
/home/developer/workspace/test/glaze/release/_deps/glaze-src/include/glaze/json/json_ptr.hpp:514:102: internal compiler error: Segmentation fault
514 | using G = member_getter<V, glz::detail::string_literal_from_view<key_str.size()>(key_str)>;
| ^
0x7f275468208f ???
/build/glibc-SzIz7B/glibc-2.31/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
0x7f2754663082 __libc_start_main
../csu/libc-start.c:308
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.

In the project I would like to use glaze I'm restricted to gcc 10.3.0 at this moment.
Is there a way to work-around this issue?

You should be able to reproduce this using the code snippet:

#include <glaze/glaze.hpp>

int main()
{

    glz::recorder<double, float> rec;

    double x = 0.0;
    float y = 0.f;

    rec["x"] = x;
    rec["y"] = y;

    for (int i = 0; i < 100; ++i) {
       x += 1.5;
       y += static_cast<float>(i);
       rec.update(); // saves the current state of x and y
    }

    glz::write_file_json(rec, "recorder_out.json");
    
}

gcc std::declval issues

It looks like gcc has some issues with std::declval, which I'm not sure how to get around.
Specifically this line return std::declval<T>().*mptr_type{}; in member_check in common.hpp. gcc seems to think this std::declval is being evaluated, even when I make the function consteval. Until gcc fixes the bug or I figure out a work around gcc just won't work yet. clang and MSVC should be working fine.

Originally posted by @stephenberry in #4 (comment)

Please include <climits> for CHAR_BIT

glaze/api/hash.hpp uses CHAR_BIT.

   template <class T, T Value, size_t... Is>
   consteval auto make_array_impl(std::index_sequence<Is...>) {
      return std::array<char, sizeof(T)>{ static_cast<char>(((Value >> (CHAR_BIT * Is)) & 0xff))... };
   }

CHAR_BIT is defined in <climits>.
Before 0.2.4, it was included by fmtlib.
Because glaze doesn't require fmtlib since 0.2.4, there is no explicit place where includes <climits>.
This causes compilation error in several environments.

Could you include <climits>? (ex. glaze/api/hash.hpp)

String deduplication?

Use a custom string class with a memory pool for string deduplication, reducing memory overhead.

Error when building with g++ 12.2.1

With g++ 12.2.1 the building fails:

$ git clone https://github.com/stephenberry/glaze
Cloning into 'glaze'...
remote: Enumerating objects: 5104, done.
remote: Counting objects: 100% (458/458), done.
remote: Compressing objects: 100% (206/206), done.
remote: Total 5104 (delta 312), reused 297 (delta 239), pack-reused 4646
Receiving objects: 100% (5104/5104), 1.41 MiB | 563.00 KiB/s, done.
Resolving deltas: 100% (3245/3245), done.
$ cd glaze
$ git rev-parse HEAD
ce50dbd6f1c12271df2e8f8bdc7c53b43143e45c
$ mkdir build
$ cd build
$ cmake ..
-- The CXX compiler identification is GNU 12.2.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/lib64/ccache/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Fetching dependencies...
-- Downloading CPM.cmake to /tmp/f/glaze/build/cmake/CPM_0.36.0.cmake
-- CPM: adding package [email protected] (v1.10.0)
-- ...finished fetching dependencies.
-- The C compiler identification is GNU 12.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/lib64/ccache/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/f/glaze/build
$ make
[  7%] Building CXX object CMakeFiles/glaze_ide.dir/src/main.cpp.o
[ 14%] Linking CXX executable glaze_ide
[ 14%] Built target glaze_ide
[ 21%] Building CXX object tests/api_test/CMakeFiles/api_test.dir/api_test.cpp.o
[ 28%] Linking CXX executable api_test
[ 28%] Built target api_test
[ 35%] Building CXX object tests/binary_test/CMakeFiles/binary_test.dir/binary_test.cpp.o
[ 42%] Linking CXX executable binary_test
[ 42%] Built target binary_test
[ 50%] Building CXX object tests/eigen_test/CMakeFiles/eigen_test.dir/eigen_test.cpp.o
[ 57%] Linking CXX executable eigen_test
[ 57%] Built target eigen_test
[ 64%] Building CXX object tests/json_test/CMakeFiles/json_test.dir/json_test.cpp.o
In file included from /tmp/f/glaze/include/glaze/core/meta.hpp:8,
                 from /tmp/f/glaze/include/glaze/core/common.hpp:20,
                 from /tmp/f/glaze/include/glaze/json/json_ptr.hpp:10,
                 from /tmp/f/glaze/tests/json_test/json_test.cpp:16:
/tmp/f/glaze/include/glaze/util/type_traits.hpp: In instantiation of ‘constexpr auto glz::get_argument() [with auto MemPtr = &animal::eat]’:
/tmp/f/glaze/include/glaze/util/poly.hpp:26:163:   required from ‘constexpr auto glz::make_mem_fn_wrapper_map_impl(std::index_sequence<Is ...>) [with Spec = animal; long unsigned int ...I = {0, 1}; std::index_sequence<Is ...> = std::integer_sequence<long unsigned int, 0, 1>]’
/tmp/f/glaze/include/glaze/util/poly.hpp:33:48:   required from ‘constexpr auto glz::make_mem_fn_wrapper_map() [with Spec = animal]’
/tmp/f/glaze/include/glaze/util/poly.hpp:98:65:   required from ‘constexpr const auto glz::poly<animal>::cmap’
/tmp/f/glaze/include/glaze/util/poly.hpp:98:29:   required from ‘struct glz::poly<animal>’
/usr/include/c++/12/array:115:56:   required from ‘struct std::array<glz::poly<animal>, 2>’
/tmp/f/glaze/tests/json_test/json_test.cpp:2818:40:   required from here
/tmp/f/glaze/include/glaze/util/type_traits.hpp:128:42: error: invalid conversion from ‘void (*)(void*)’ to ‘decltype(auto) (*)(void*)’ [-fpermissive]
  128 |          return arguments<MemPtr, Type>::op;
      |                                          ^~
      |                                          |
      |                                          void (*)(void*)
In file included from /tmp/f/glaze/include/glaze/json/json_ptr.hpp:13:
/tmp/f/glaze/include/glaze/util/poly.hpp: In instantiation of ‘constexpr auto glz::make_mem_fn_wrapper_map_impl(std::index_sequence<Is ...>) [with Spec = animal; long unsigned int ...I = {0, 1}; std::index_sequence<Is ...> = std::integer_sequence<long unsigned int, 0, 1>]’:
/tmp/f/glaze/include/glaze/util/poly.hpp:33:48:   required from ‘constexpr auto glz::make_mem_fn_wrapper_map() [with Spec = animal]’
/tmp/f/glaze/include/glaze/util/poly.hpp:98:65:   required from ‘constexpr const auto glz::poly<animal>::cmap’
/tmp/f/glaze/include/glaze/util/poly.hpp:98:29:   required from ‘struct glz::poly<animal>’
/usr/include/c++/12/array:115:56:   required from ‘struct std::array<glz::poly<animal>, 2>’
/tmp/f/glaze/tests/json_test/json_test.cpp:2818:40:   required from here
/tmp/f/glaze/include/glaze/util/poly.hpp:26:163: error: use of ‘constexpr auto glz::get_argument() [with auto MemPtr = &animal::eat]’ before deduction of ‘auto’
   26 |          std::make_pair<frozen::string, fn_variant<Spec>>(tuplet::get<0>(tuplet::get<I>(meta_v<Spec>)), get_argument<tuplet::get<1>(tuplet::get<I>(meta_v<Spec>))>())...
      |                                                                                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
/tmp/f/glaze/include/glaze/util/poly.hpp:25:77: error: no matching function for call to ‘make_unordered_map<glz::frozen::string, glz::fn_variant<animal>, N>(<brace-enclosed initializer list>)’
   25 |       return frozen::make_unordered_map<frozen::string, fn_variant<Spec>, N>({
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
   26 |          std::make_pair<frozen::string, fn_variant<Spec>>(tuplet::get<0>(tuplet::get<I>(meta_v<Spec>)), get_argument<tuplet::get<1>(tuplet::get<I>(meta_v<Spec>))>())...
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   27 |       });
      |       ~~                                                                     
In file included from /tmp/f/glaze/include/glaze/core/common.hpp:17:
/tmp/f/glaze/include/glaze/frozen/unordered_map.hpp:248:19: note: candidate: ‘constexpr auto glz::frozen::make_unordered_map(const std::pair<_T1, _T2> (&)[N]) [with T = basic_string<char>; U = std::variant<int*, void (*)(void*)>; long unsigned int N = 2]’
  248 |    constexpr auto make_unordered_map(std::pair<T, U> const (&items)[N]) {
      |                   ^~~~~~~~~~~~~~~~~~
/tmp/f/glaze/include/glaze/frozen/unordered_map.hpp:248:62: note:   no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘const std::pair<glz::frozen::basic_string<char>, std::variant<int*, void (*)(void*)> > (&)[2]’
  248 |    constexpr auto make_unordered_map(std::pair<T, U> const (&items)[N]) {
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
/tmp/f/glaze/include/glaze/frozen/unordered_map.hpp:253:19: note: candidate: ‘template<class T, class U, long unsigned int N, class Hasher, class Equal> constexpr auto glz::frozen::make_unordered_map(const std::pair<_T1, _T2> (&)[N], const Hasher&, const Equal&)’
  253 |    constexpr auto make_unordered_map(
      |                   ^~~~~~~~~~~~~~~~~~
/tmp/f/glaze/include/glaze/frozen/unordered_map.hpp:253:19: note:   template argument deduction/substitution failed:
/tmp/f/glaze/include/glaze/util/poly.hpp:25:77: note:   couldn’t deduce template parameter ‘Hasher’
   25 |       return frozen::make_unordered_map<frozen::string, fn_variant<Spec>, N>({
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
   26 |          std::make_pair<frozen::string, fn_variant<Spec>>(tuplet::get<0>(tuplet::get<I>(meta_v<Spec>)), get_argument<tuplet::get<1>(tuplet::get<I>(meta_v<Spec>))>())...
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   27 |       });
      |       ~~                                                                     
/tmp/f/glaze/include/glaze/frozen/unordered_map.hpp:261:19: note: candidate: ‘constexpr auto glz::frozen::make_unordered_map(const std::array<std::pair<_T1, _T2>, N>&) [with T = basic_string<char>; U = std::variant<int*, void (*)(void*)>; long unsigned int N = 2]’
  261 |    constexpr auto make_unordered_map(std::array<std::pair<T, U>, N> const &items) {
      |                   ^~~~~~~~~~~~~~~~~~
/tmp/f/glaze/include/glaze/frozen/unordered_map.hpp:261:76: note:   no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘const std::array<std::pair<glz::frozen::basic_string<char>, std::variant<int*, void (*)(void*)> >, 2>&’
  261 |    constexpr auto make_unordered_map(std::array<std::pair<T, U>, N> const &items) {
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
/tmp/f/glaze/include/glaze/frozen/unordered_map.hpp:266:19: note: candidate: ‘template<class T, class U, long unsigned int N, class Hasher, class Equal> constexpr auto glz::frozen::make_unordered_map(const std::array<std::pair<_T1, _T2>, N>&, const Hasher&, const Equal&)’
  266 |    constexpr auto make_unordered_map(
      |                   ^~~~~~~~~~~~~~~~~~
/tmp/f/glaze/include/glaze/frozen/unordered_map.hpp:266:19: note:   template argument deduction/substitution failed:
/tmp/f/glaze/include/glaze/util/poly.hpp:25:77: note:   couldn’t deduce template parameter ‘Hasher’
   25 |       return frozen::make_unordered_map<frozen::string, fn_variant<Spec>, N>({
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
   26 |          std::make_pair<frozen::string, fn_variant<Spec>>(tuplet::get<0>(tuplet::get<I>(meta_v<Spec>)), get_argument<tuplet::get<1>(tuplet::get<I>(meta_v<Spec>))>())...
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   27 |       });
      |       ~~                                                                     
/tmp/f/glaze/include/glaze/util/poly.hpp: In instantiation of ‘decltype(auto) glz::poly<Spec>::call(Args&& ...) [with string_literal<...auto...> name = glz::string_literal<4>{"eat"}; Args = {}; Spec = animal]’:
/tmp/f/glaze/tests/json_test/json_test.cpp:2820:23:   required from here
/tmp/f/glaze/include/glaze/util/poly.hpp:109:43: error: using invalid field ‘glz::poly<Spec>::map’
  109 |             auto* v = reinterpret_cast<X>(map[index].fptr);
      |                                           ^~~
/tmp/f/glaze/include/glaze/util/poly.hpp:115:30: error: static assertion failed: call: invalid arguments to call
  115 |                static_assert(false_v<decltype(name)>, "call: invalid arguments to call");
      |                              ^~~~~~~~~~~~~~~~~~~~~~~
/tmp/f/glaze/include/glaze/util/poly.hpp:115:30: note: ‘glz::false_v<const glz::string_literal<4> >’ evaluates to false
/tmp/f/glaze/include/glaze/util/poly.hpp:119:27: error: static assertion failed: call: invalid name
  119 |             static_assert(false_v<decltype(name)>, "call: invalid name");
      |                           ^~~~~~~~~~~~~~~~~~~~~~~
/tmp/f/glaze/include/glaze/util/poly.hpp:119:27: note: ‘glz::false_v<const glz::string_literal<4> >’ evaluates to false
/tmp/f/glaze/include/glaze/util/poly.hpp: In instantiation of ‘decltype(auto) glz::poly<Spec>::get() [with string_literal<...auto...> name = glz::string_literal<4>{"age"}; Spec = animal]’:
/tmp/f/glaze/tests/json_test/json_test.cpp:2823:29:   required from here
/tmp/f/glaze/include/glaze/util/poly.hpp:131:43: error: using invalid field ‘glz::poly<Spec>::map’
  131 |             auto* v = reinterpret_cast<X>(map[index].ptr);
      |                                           ^~~
/tmp/f/glaze/include/glaze/util/poly.hpp:135:27: error: static assertion failed: call: invalid name
  135 |             static_assert(false_v<decltype(name)>, "call: invalid name");
      |                           ^~~~~~~~~~~~~~~~~~~~~~~
/tmp/f/glaze/include/glaze/util/poly.hpp:135:27: note: ‘glz::false_v<const glz::string_literal<4> >’ evaluates to false
/tmp/f/glaze/include/glaze/util/type_traits.hpp: In instantiation of ‘constexpr auto glz::get_argument() [with auto MemPtr = &string_t::string]’:
/tmp/f/glaze/include/glaze/util/poly.hpp:26:163:   required from ‘constexpr auto glz::make_mem_fn_wrapper_map_impl(std::index_sequence<Is ...>) [with Spec = string_t; long unsigned int ...I = {0}; std::index_sequence<Is ...> = std::integer_sequence<long unsigned int, 0>]’
/tmp/f/glaze/include/glaze/util/poly.hpp:33:48:   required from ‘constexpr auto glz::make_mem_fn_wrapper_map() [with Spec = string_t]’
/tmp/f/glaze/include/glaze/util/poly.hpp:98:65:   required from ‘constexpr const auto glz::poly<string_t>::cmap’
/tmp/f/glaze/include/glaze/util/poly.hpp:98:29:   required from ‘struct glz::poly<string_t>’
/tmp/f/glaze/tests/json_test/json_test.cpp:2845:27:   required from here
/tmp/f/glaze/include/glaze/util/type_traits.hpp:128:42: error: invalid conversion from ‘std::__cxx11::basic_string<char> (*)(void*, std::decay_t<std::basic_string_view<char> >&&, std::decay_t<int>&&)’ {aka ‘std::__cxx11::basic_string<char> (*)(void*, std::decay<std::basic_string_view<char> >::type&&, int&&)’} to ‘decltype(auto) (*)(void*, std::basic_string_view<char>&&, int&&)’ [-fpermissive]
  128 |          return arguments<MemPtr, Type>::op;
      |                                          ^~
      |                                          |
      |                                          std::__cxx11::basic_string<char> (*)(void*, std::decay_t<std::basic_string_view<char> >&&, std::decay_t<int>&&) {aka std::__cxx11::basic_string<char> (*)(void*, std::decay<std::basic_string_view<char> >::type&&, int&&)}
/tmp/f/glaze/include/glaze/util/poly.hpp: In instantiation of ‘constexpr auto glz::make_mem_fn_wrapper_map_impl(std::index_sequence<Is ...>) [with Spec = string_t; long unsigned int ...I = {0}; std::index_sequence<Is ...> = std::integer_sequence<long unsigned int, 0>]’:
/tmp/f/glaze/include/glaze/util/poly.hpp:33:48:   required from ‘constexpr auto glz::make_mem_fn_wrapper_map() [with Spec = string_t]’
/tmp/f/glaze/include/glaze/util/poly.hpp:98:65:   required from ‘constexpr const auto glz::poly<string_t>::cmap’
/tmp/f/glaze/include/glaze/util/poly.hpp:98:29:   required from ‘struct glz::poly<string_t>’
/tmp/f/glaze/tests/json_test/json_test.cpp:2845:27:   required from here
/tmp/f/glaze/include/glaze/util/poly.hpp:26:163: error: use of ‘constexpr auto glz::get_argument() [with auto MemPtr = &string_t::string]’ before deduction of ‘auto’
   26 |          std::make_pair<frozen::string, fn_variant<Spec>>(tuplet::get<0>(tuplet::get<I>(meta_v<Spec>)), get_argument<tuplet::get<1>(tuplet::get<I>(meta_v<Spec>))>())...
      |                                                                                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
/tmp/f/glaze/include/glaze/util/poly.hpp:25:77: error: no matching function for call to ‘make_unordered_map<glz::frozen::string, glz::fn_variant<string_t>, N>(<brace-enclosed initializer list>)’
   25 |       return frozen::make_unordered_map<frozen::string, fn_variant<Spec>, N>({
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
   26 |          std::make_pair<frozen::string, fn_variant<Spec>>(tuplet::get<0>(tuplet::get<I>(meta_v<Spec>)), get_argument<tuplet::get<1>(tuplet::get<I>(meta_v<Spec>))>())...
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   27 |       });
      |       ~~                                                                     
/tmp/f/glaze/include/glaze/frozen/unordered_map.hpp:248:19: note: candidate: ‘constexpr auto glz::frozen::make_unordered_map(const std::pair<_T1, _T2> (&)[N]) [with T = basic_string<char>; U = std::variant<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > (*)(void*, std::basic_string_view<char, std::char_traits<char> >&&, int&&)>; long unsigned int N = 1]’
  248 |    constexpr auto make_unordered_map(std::pair<T, U> const (&items)[N]) {
      |                   ^~~~~~~~~~~~~~~~~~
/tmp/f/glaze/include/glaze/frozen/unordered_map.hpp:248:62: note:   no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘const std::pair<glz::frozen::basic_string<char>, std::variant<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > (*)(void*, std::basic_string_view<char, std::char_traits<char> >&&, int&&)> > (&)[1]’
  248 |    constexpr auto make_unordered_map(std::pair<T, U> const (&items)[N]) {
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
/tmp/f/glaze/include/glaze/frozen/unordered_map.hpp:253:19: note: candidate: ‘template<class T, class U, long unsigned int N, class Hasher, class Equal> constexpr auto glz::frozen::make_unordered_map(const std::pair<_T1, _T2> (&)[N], const Hasher&, const Equal&)’
  253 |    constexpr auto make_unordered_map(
      |                   ^~~~~~~~~~~~~~~~~~
/tmp/f/glaze/include/glaze/frozen/unordered_map.hpp:253:19: note:   template argument deduction/substitution failed:
/tmp/f/glaze/include/glaze/util/poly.hpp:25:77: note:   couldn’t deduce template parameter ‘Hasher’
   25 |       return frozen::make_unordered_map<frozen::string, fn_variant<Spec>, N>({
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
   26 |          std::make_pair<frozen::string, fn_variant<Spec>>(tuplet::get<0>(tuplet::get<I>(meta_v<Spec>)), get_argument<tuplet::get<1>(tuplet::get<I>(meta_v<Spec>))>())...
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   27 |       });
      |       ~~                                                                     
/tmp/f/glaze/include/glaze/frozen/unordered_map.hpp:261:19: note: candidate: ‘constexpr auto glz::frozen::make_unordered_map(const std::array<std::pair<_T1, _T2>, N>&) [with T = basic_string<char>; U = std::variant<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > (*)(void*, std::basic_string_view<char, std::char_traits<char> >&&, int&&)>; long unsigned int N = 1]’
  261 |    constexpr auto make_unordered_map(std::array<std::pair<T, U>, N> const &items) {
      |                   ^~~~~~~~~~~~~~~~~~
/tmp/f/glaze/include/glaze/frozen/unordered_map.hpp:261:76: note:   no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘const std::array<std::pair<glz::frozen::basic_string<char>, std::variant<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > (*)(void*, std::basic_string_view<char, std::char_traits<char> >&&, int&&)> >, 1>&’
  261 |    constexpr auto make_unordered_map(std::array<std::pair<T, U>, N> const &items) {
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
/tmp/f/glaze/include/glaze/frozen/unordered_map.hpp:266:19: note: candidate: ‘template<class T, class U, long unsigned int N, class Hasher, class Equal> constexpr auto glz::frozen::make_unordered_map(const std::array<std::pair<_T1, _T2>, N>&, const Hasher&, const Equal&)’
  266 |    constexpr auto make_unordered_map(
      |                   ^~~~~~~~~~~~~~~~~~
/tmp/f/glaze/include/glaze/frozen/unordered_map.hpp:266:19: note:   template argument deduction/substitution failed:
/tmp/f/glaze/include/glaze/util/poly.hpp:25:77: note:   couldn’t deduce template parameter ‘Hasher’
   25 |       return frozen::make_unordered_map<frozen::string, fn_variant<Spec>, N>({
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
   26 |          std::make_pair<frozen::string, fn_variant<Spec>>(tuplet::get<0>(tuplet::get<I>(meta_v<Spec>)), get_argument<tuplet::get<1>(tuplet::get<I>(meta_v<Spec>))>())...
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   27 |       });
      |       ~~                                                                     
/tmp/f/glaze/include/glaze/util/poly.hpp: In instantiation of ‘decltype(auto) glz::poly<Spec>::call(Args&& ...) [with string_literal<...auto...> name = glz::string_literal<7>{"string"}; Args = {const char (&)[2], int}; Spec = string_t]’:
/tmp/f/glaze/tests/json_test/json_test.cpp:2847:30:   required from here
/tmp/f/glaze/include/glaze/util/poly.hpp:109:43: error: using invalid field ‘glz::poly<Spec>::map’
  109 |             auto* v = reinterpret_cast<X>(map[index].fptr);
      |                                           ^~~
/tmp/f/glaze/include/glaze/util/poly.hpp:115:30: error: static assertion failed: call: invalid arguments to call
  115 |                static_assert(false_v<decltype(name)>, "call: invalid arguments to call");
      |                              ^~~~~~~~~~~~~~~~~~~~~~~
/tmp/f/glaze/include/glaze/util/poly.hpp:115:30: note: ‘glz::false_v<const glz::string_literal<7> >’ evaluates to false
/tmp/f/glaze/include/glaze/util/poly.hpp:119:27: error: static assertion failed: call: invalid name
  119 |             static_assert(false_v<decltype(name)>, "call: invalid name");
      |                           ^~~~~~~~~~~~~~~~~~~~~~~
/tmp/f/glaze/include/glaze/util/poly.hpp:119:27: note: ‘glz::false_v<const glz::string_literal<7> >’ evaluates to false
make[2]: *** [tests/json_test/CMakeFiles/json_test.dir/build.make:76: tests/json_test/CMakeFiles/json_test.dir/json_test.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:1124: tests/json_test/CMakeFiles/json_test.dir/all] Error 2
make: *** [Makefile:166: all] Error 2
$ g++ --version
g++ (GCC) 12.2.1 20221121 (Red Hat 12.2.1-4)
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ 

If I use clang by setting environment variable CXX=clang++, the building succeeds normally, clang version is:

$ clang++ --version
clang version 14.0.5 (Fedora 14.0.5-2.fc36)
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$

Const vs non-const json_t

Not sure if this is intended or not, but using const glz::json_t seems to behave differently than non-const glz::json_t, for example:

$ cat g.cc
#include <iostream>
#include <glaze/glaze.hpp>

static void foo(const glz::json_t & json)
{
  std::cout << json["s"].get<std::string>() << "\n";
}
int main()
{
  glz::json_t json = { {"s", "hello world"} };
  std::cout << json["s"].get<std::string>() << "\n";
  foo(json);
}
$ g++ --std=c++20 g.cc
g.cc: In function ‘void foo(const glz::json_t&)’:
g.cc:6:26: error: request for member ‘get’ in ‘*(((const char*)"s") + ((sizetype)(& json)->glz::json_t::operator bool()))’, which is of non-class type ‘const char’
    6 |   std::cout << json["s"].get<std::string>() << "\n";
      |                          ^~~
g.cc:6:41: error: expected primary-expression before ‘>’ token
    6 |   std::cout << json["s"].get<std::string>() << "\n";
      |                                         ^
g.cc:6:43: error: expected primary-expression before ‘)’ token
    6 |   std::cout << json["s"].get<std::string>() << "\n";
      |                                           ^
$ g++ --version
g++ (GCC) 12.2.1 20221121 (Red Hat 12.2.1-4)
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ 

If I remove the const from the parameter to foo(), then it compiles and prints hello world twice as I expected:

[joyr@hot libfmsynth]$ cat g2.cc
#include <iostream>
#include <glaze/glaze.hpp>

static void foo(glz::json_t & json)
{
  std::cout << json["s"].get<std::string>() << "\n";
}

int main()
{
  glz::json_t json = { {"s", "hello world"} };
  std::cout << json["s"].get<std::string>() << "\n";
  foo(json);
}
$ g++ --std=c++20 g2.cc
$ ./a.out 
hello world
hello world
$ diff g.cc g2.cc
4c4
< static void foo(const glz::json_t & json)
---
> static void foo(glz::json_t & json)
$ 

Shorter test case without function:

$ cat g3.cc
#include <iostream>
#include <glaze/glaze.hpp>

int main()
{
  const glz::json_t json = { {"s", "hello world"} };
  std::cout << json["s"].get<std::string>() << "\n";
}
$ g++ -std=c++20 g3.cc
g3.cc: In function ‘int main()’:
g3.cc:7:26: error: request for member ‘get’ in ‘*(((const char*)"s") + ((sizetype)json.glz::json_t::operator bool()))’, which is of non-class type ‘const char’
    7 |   std::cout << json["s"].get<std::string>() << "\n";
      |                          ^~~
g3.cc:7:41: error: expected primary-expression before ‘>’ token
    7 |   std::cout << json["s"].get<std::string>() << "\n";
      |                                         ^
g3.cc:7:43: error: expected primary-expression before ‘)’ token
    7 |   std::cout << json["s"].get<std::string>() << "\n";
      |                                           ^
$ 

Hash performance on glaze_objects with small number of keys.

This is based on conversations I have had outside of github with @stephenberry and Im adding it here to be tracked. We have seen that a naive space inefficient constexpr perfect hash table can get better lookup perf (~2x) than frozen unordered_map when there are a small number of compile-time known keys. Performance disparity should exist for greater numbers of keys but either space or compiletime requirements grow too rapidly for it to be feasible. This should affect object json read perf as Ive seen the map lookup time take anywhere from 5-50% of the runtime depending on the complexity of the object.

There is another potential optimization but it can cause problems in corner cases. We can get further performance on long keys by changing the key validity test. We already have the correct table key hashes compiletime and the input key hash is calculated each lookup so a hash test is very cheap on large keys and while not perfect is probably good enough. This is opposed to the sting equality test used by default in frozen. Correct key hashes cannot collide due to perfect hashing but invalid keys have a small chance (~1/(2^64)) to collide but are generally unexpected so I think the hash test is good enough but we should probably only support this as a compile time option as it is incorrect.

I suggest we implement a small naive perfect hash map that follows a subset of the frozen api that can be used when we know key sizes are low (<10 or so) and then switch to frozen (using "if constexpr") when key sizes in glaze objects are large. This should not affect end users since all the constxepr map stuff is internal and part of the detail impl.

Support for any type?

Hi,

There is a way to have something like this as i do in Kotlin?

class Param(val n: String, val v: Any)

val request = Request(
    "test1",
    Param("username", "paulo"),
    Param("password", "123456"),
    Param("remember", true)
)

val gson = Gson()
val str = gson.toJson(request)

Thanks.

About exceptions handling

I found that glaze is throwing exceptions by default. First looking at the code and repo, I find that glaze doesn't support exception-free mode. Is it possible to implement that for using glaze in projects with no exceptions?

glaze/include/glaze/util/parse.hpp:262:48: error: exception handling disabled, use ‘-fexceptions’ to enable
  262 |          throw std::runtime_error("not a digit");

Remove fast_float and dragonbox dependencies.

Right now not all from_chars and to_chars implementations use the cutting edge methods for number conversions. When clang/gcc/msvc are all up to snuff perf/completeness wise we will switch to those methods. In the meantime I think I will create a numconv shim based on the current best methodologies I can find that is tailored to our use cases. For one we want to handle exponents in ints (1e10) without relying on using a floating point parser (Precise floating point parsing tends to be much slower since its a very hard problem).

Build failure on Windows C++/WinRT

I tried to use glaze in my WinUI3 project, but I found that the compilation does not pass, while I tested in a normal C++ project that it can compile and run(The C++ version of both projects is set to c++20). I'm new to C++ and I don't know how to deal with this problem

Error Output

2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(136,76): error C2589: '(': illegal token on right side of '::' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(136,76): error C2062: type 'unknown-type' unexpected (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(136,41): error C2789: 'glz::frozen::bits::seed_or_index::MINUS_ONE': an object of const-qualified type must be initialized (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
       D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(136,31): message : see declaration of 'glz::frozen::bits::seed_or_index::MINUS_ONE' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(136,76): error C2059: syntax error: ')' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(137,42): error C2131: expression did not evaluate to a constant (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
       D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(137,44): message : failure was caused by a read of an uninitialized symbol (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
       D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(137,44): message : see usage of 'MINUS_ONE' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): warning C4003: not enough arguments for function-like macro invocation 'max' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): error C2589: '(': illegal token on right side of '::' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): error C[276](https://github.com/axojhf/GlazeTestWinRT/actions/runs/4211692824/jobs/7310203467#step:5:277)0: syntax error: ')' was unexpected here; expected 'expression' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): error C2760: syntax error: ')' was unexpected here; expected ';' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): error C3878: syntax error: unexpected token ')' following 'expression_statement' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
       D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): message : error recovery skipped: ') >' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
       D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): message : error recovery skipped: ') ) ?' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
       D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): message : error recovery skipped: ') :' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
       D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): message : error recovery skipped: ') )' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(74,35): warning C4003: not enough arguments for function-like macro invocation 'min' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(75,35): warning C4003: not enough arguments for function-like macro invocation 'max' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(74,35): error C2059: syntax error: ')' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
       D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(87,5): message : see reference to class template instantiation 'glz::frozen::linear_congruential_engine<UIntType,a,c,m>' being compiled (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(74,1): error C2334: unexpected token(s) preceding ':'; skipping apparent function body (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(87,4): error C2143: syntax error: missing ')' before ';' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(87,4): error C2059: syntax error: ')' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(87,4): error C2238: unexpected token(s) preceding ';' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(87,4): fatal  error C1201: unable to continue after syntax error in class template definition (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         module.g.cpp
         XamlTypeInfo.Impl.g.cpp
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(136,76): warning C4003: not enough arguments for function-like macro invocation 'max' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(136,76): error C2589: '(': illegal token on right side of '::' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(136,76): error C2062: type 'unknown-type' unexpected (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(136,41): error C[278](https://github.com/axojhf/GlazeTestWinRT/actions/runs/4211692824/jobs/7310203467#step:5:279)9: 'glz::frozen::bits::seed_or_index::MINUS_ONE': an object of const-qualified type must be initialized (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
       D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(136,31): message : see declaration of 'glz::frozen::bits::seed_or_index::MINUS_ONE' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(136,76): error C2059: syntax error: ')' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(137,42): error C2131: expression did not evaluate to a constant (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
       D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(137,44): message : failure was caused by a read of an uninitialized symbol (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
       D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(137,44): message : see usage of 'MINUS_ONE' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): warning C4003: not enough arguments for function-like macro invocation 'max' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): error C2589: '(': illegal token on right side of '::' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): error C2760: syntax error: ')' was unexpected here; expected 'expression' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): error C2760: syntax error: ')' was unexpected here; expected ';' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): error C3878: syntax error: unexpected token ')' following 'expression_statement' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
       D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): message : error recovery skipped: ') >' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
       D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): message : error recovery skipped: ') ) ?' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
       D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): message : error recovery skipped: ') :' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
       D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): message : error recovery skipped: ') )' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(74,35): warning C4003: not enough arguments for function-like macro invocation 'min' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(75,35): warning C4003: not enough arguments for function-like macro invocation 'max' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(74,35): error C2059: syntax error: ')' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
       D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(87,5): message : see reference to class template instantiation 'glz::frozen::linear_congruential_engine<UIntType,a,c,m>' being compiled (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(74,1): error C2[334](https://github.com/axojhf/GlazeTestWinRT/actions/runs/4211692824/jobs/7310203467#step:5:335): unexpected token(s) preceding ':'; skipping apparent function body (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(87,4): error C2143: syntax error: missing ')' before ';' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(87,4): error C2059: syntax error: ')' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(87,4): error C2238: unexpected token(s) preceding ';' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(87,4): fatal  error C1201: unable to continue after syntax error in class template definition (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
     2>Done Building Project "D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj" (default targets) -- FAILED.
     1>Done Building Project "D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.sln" (default targets) -- FAILED.

Build FAILED.

       "D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.sln" (default target) (1) ->
       "D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj" (default target) (2) ->
       (ClCompile target) -> 
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(136,76): warning C4003: not enough arguments for function-like macro invocation 'max' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): warning C4003: not enough arguments for function-like macro invocation 'max' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(74,35): warning C4003: not enough arguments for function-like macro invocation 'min' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(75,35): warning C4003: not enough arguments for function-like macro invocation 'max' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(136,76): warning C4003: not enough arguments for function-like macro invocation 'max' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): warning C4003: not enough arguments for function-like macro invocation 'max' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(74,35): warning C4003: not enough arguments for function-like macro invocation 'min' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(75,35): warning C4003: not enough arguments for function-like macro invocation 'max' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]


       "D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.sln" (default target) (1) ->
       "D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj" (default target) (2) ->
       (ClCompile target) -> 
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(136,76): error C2589: '(': illegal token on right side of '::' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(136,76): error C2062: type 'unknown-type' unexpected (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(136,41): error C2789: 'glz::frozen::bits::seed_or_index::MINUS_ONE': an object of const-qualified type must be initialized (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(136,76): error C2059: syntax error: ')' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(137,42): error C2131: expression did not evaluate to a constant (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): error C2589: '(': illegal token on right side of '::' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): error C2760: syntax error: ')' was unexpected here; expected 'expression' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): error C2760: syntax error: ')' was unexpected here; expected ';' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): error C3878: syntax error: unexpected token ')' following 'expression_statement' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(74,35): error C2059: syntax error: ')' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(74,1): error C2334: unexpected token(s) preceding ':'; skipping apparent function body (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(87,4): error C2143: syntax error: missing ')' before ';' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(87,4): error C2059: syntax error: ')' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(87,4): error C2238: unexpected token(s) preceding ';' (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(87,4): fatal  error C1201: unable to continue after syntax error in class template definition (compiling source file MainWindow.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(136,76): error C2589: '(': illegal token on right side of '::' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(136,76): error C2062: type 'unknown-type' unexpected (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(136,41): error C2789: 'glz::frozen::bits::seed_or_index::MINUS_ONE': an object of const-qualified type must be initialized (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(136,76): error C2059: syntax error: ')' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(137,42): error C2131: expression did not evaluate to a constant (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): error C2589: '(': illegal token on right side of '::' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): error C2760: syntax error: ')' was unexpected here; expected 'expression' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): error C2760: syntax error: ')' was unexpected here; expected ';' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\bits\pmh.hpp(193,68): error C3878: syntax error: unexpected token ')' following 'expression_statement' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(74,35): error C2059: syntax error: ')' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(74,1): error C2334: unexpected token(s) preceding ':'; skipping apparent function body (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(87,4): error C2143: syntax error: missing ')' before ';' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(87,4): error C2059: syntax error: ')' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(87,4): error C2238: unexpected token(s) preceding ';' (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]
         D:\a\GlazeTestWinRT\GlazeTestWinRT\thirdparts\glaze\frozen\random.hpp(87,4): fatal  error C1201: unable to continue after syntax error in class template definition (compiling source file App.xaml.cpp) [D:\a\GlazeTestWinRT\GlazeTestWinRT\GlazeTestWinRT.vcxproj]

    8 Warning(s)
    30 Error(s)

any plan support idl file?

automatically output the corresponding structure according to idl,no need to manually enter the following code

template <>
struct glz::meta<my_struct> {
   using T = my_struct;
   static constexpr auto value = object(
      "i", &T::i,
      "d", &T::d,
      "hello", &T::hello,
      "arr", &T::arr
   );

Any plan to support NDJSON?

Hello.
I think glaze is a great library.
I have started to use glaze when I write new programs.
Next phase, I would like to replace other libraries with glaze in existing programs where speed is important, but NDJSON(Newline Delimited JSON) support is an issue.
http://ndjson.org/

As far as I know, glaze does not support NDJSON.
Are there any plans to support NDJSON?

Nested objects in glz::json_t result in 'std::length_error` exception

Hey!
So I am trying to parse a schema into the glz::json_t object. This will be better explained in code:

static const glz::json_t messageSchema = {
    {"type","struct"},
    {"fields", {
        {{"field","branch"}, {"type","string"}},
        }
    }
};

This results in:

terminate called after throwing an instance of 'std::length_error'
  what():  basic_string::_S_create

If I try to do it like this (without extra brackets around {"field","branch"}, {"type","string"}) it works, but not what I want:

static const glz::json_t messageSchema = {
    {"type","struct"},
    {"fields", {
        {"field","branch"}, {"type","string"},
        }
    }
};

Does the glz::json_t have issues with nesting and if you have any suggestions on how to fix it? That would be much appreciated!

EDIT:

    glz::json_t messageSchema;
    glz::json_t field1 = {{"field", "branch"}, {"type", "string"}};
    messageSchema["type"]  = "struct";
    messageSchema["fields"] = {field1};

This does work though!

glaze macro not working

Hi

Thanks for the awsome contributions, howerver, the macro dose not work. The test code sourced from glaze_example

cmake

cmake_minimum_required(VERSION 3.18)

project(
   glaze_example
   VERSION 0.0.1
   LANGUAGES CXX
)

file(GLOB srcs src/*.cpp include/*.hpp)

include(FetchContent)

FetchContent_Declare(
  glaze
  GIT_REPOSITORY https://github.com/stephenberry/glaze.git
  GIT_TAG main
  GIT_SHALLOW TRUE
)

FetchContent_MakeAvailable(glaze)

add_executable(${PROJECT_NAME} ${srcs})
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 20)

target_include_directories(${PROJECT_NAME} PRIVATE include)
target_link_libraries(${PROJECT_NAME} PRIVATE glaze::glaze)

example

#include "example.hpp"

struct macro_t {
   double x = 5.0;
   std::string y = "yay!";
   int z = 55;
};

GLZ_META(macro_t, x, y, z);

struct local_macro_t {
   double x = 5.0;
   std::string y = "yay!";
   int z = 55;

   GLZ_LOCAL_META(local_macro_t, x, y, z);
};

int main()
{
    return 0;
}

errors

❯ make
Consolidate compiler generated dependencies of target glaze_example
[ 50%] Building CXX object CMakeFiles/glaze_example.dir/src/example.cpp.o
/home/swei/github/json/glaze_example/src/example.cpp:9:19: error: ‘x’ has not been declared
    9 | GLZ_META(macro_t, x, y, z);
      |                   ^
/home/swei/github/json/glaze_example/src/example.cpp:9:22: error: ‘y’ has not been declared
    9 | GLZ_META(macro_t, x, y, z);
      |                      ^
/home/swei/github/json/glaze_example/src/example.cpp:9:25: error: ‘z’ has not been declared
    9 | GLZ_META(macro_t, x, y, z);
      |                         ^
/home/swei/github/json/glaze_example/src/example.cpp:9:27: error: expected constructor, destructor, or type conversion before ‘;’ token
    9 | GLZ_META(macro_t, x, y, z);
      |                           ^
/home/swei/github/json/glaze_example/src/example.cpp:16:34: error: ‘x’ is not a type
   16 |    GLZ_LOCAL_META(local_macro_t, x, y, z);
      |                                  ^
/home/swei/github/json/glaze_example/src/example.cpp:16:37: error: ‘y’ is not a type
   16 |    GLZ_LOCAL_META(local_macro_t, x, y, z);
      |                                     ^
/home/swei/github/json/glaze_example/src/example.cpp:16:40: error: ‘z’ is not a type
   16 |    GLZ_LOCAL_META(local_macro_t, x, y, z);
      |                                        ^
/home/swei/github/json/glaze_example/src/example.cpp:16:4: error: ISO C++ forbids declaration of ‘GLZ_LOCAL_META’ with no type [-fpermissive]
   16 |    GLZ_LOCAL_META(local_macro_t, x, y, z);
      |    ^~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/glaze_example.dir/build.make:76: CMakeFiles/glaze_example.dir/src/example.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:100: CMakeFiles/glaze_example.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

Unable to create json_t object with int value

I'm not able to construct json_t object when trying to initialize it with an int value:

$ cat g.cc
#include <iostream>
#include <glaze/glaze.hpp>

int main()
{
  glz::json_t json = { {"i", 1} };
  //  std::cout << json["i"].get<int>() << "\n";
}
$ g++ -std=c++20 g.cc
g.cc: In function ‘int main()’:
g.cc:6:33: error: could not convert ‘{{"i", 1}}’ from ‘<brace-enclosed initializer list>’ to ‘glz::json_t’
    6 |   glz::json_t json = { {"i", 1} };
      |                                 ^
      |                                 |
      |                                 <brace-enclosed initializer list>
$ g++ --version
g++ (GCC) 12.2.1 20221121 (Red Hat 12.2.1-4)
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ 

gcc warning ‘value’ will never be NULL

This is a strange warning, because I don't see a superfluous check. Not sure of a good way to get rid of this warning.

/home/runner/work/glaze/glaze/include/glaze/json/json_ptr.hpp:272:20: warning: the compiler can assume that the address of ‘value’ will never be NULL [-Waddress]
[42](https://github.com/stephenberry/glaze/actions/runs/3275444757/jobs/5390300069#step:4:43)
  272 |                val = value;

Add utf8 encoded json tests.

Right now everything is 100% ascii in the tests. Im not aware of anything glaze is doing that would break utf8 but wouldn't be surprised if there was any issues on this front.

write_json into vector of bytes

Hey, I'm trying to write json into a vector of bytes, so I can immediately send it to a socket, but it seems the following cases do not seem to compile:

struct TestMsg {
    uint64_t id;
    std::string val;
};

template <>
struct glz::meta<TestMsg> {
    static constexpr std::string_view name = "TestMsg";
    using T = TestMsg;
    static constexpr auto value = object(
            "id", &T::id,
            "val", &T::val
    );
};

int main() {
    std::vector<uint8_t> buffer{};
    glz::write_json(msg, buffer);
}
/home/oipo/Programming/ichor_test/glaze/include/glaze/core/write_chars.hpp:62:37: error: no matching function for call to ‘to_chars(unsigned char*&, const long unsigned int&)’
   62 |             auto end = glz::to_chars(start, value);

Changing the vector type to std::byte doesn't change much:

/home/oipo/Programming/ichor_test/glaze/include/glaze/core/write_chars.hpp:62:37: error: no matching function for call to ‘to_chars(std::byte*&, const long unsigned int&)’
   62 |             auto end = glz::to_chars(start, value);

Example fails with address sanitizer

The example taken from the front page fails with address sanitizer enabled. Error occurs with both g++ and clang++.

$ cat example.cc 
#include <glaze/glaze.hpp>

struct my_struct
{
  int i = 287;
  double d = 3.14;
  std::string hello = "Hello World";
  std::array<uint64_t, 3> arr = { 1, 2, 3 };
};

template <>
struct glz::meta<my_struct> {
   using T = my_struct;
   static constexpr auto value = object(
      "i", &T::i,
      "d", &T::d,
      "hello", &T::hello,
      "arr", &T::arr
   );
};

int main()
{
  std::string buffer = R"({"i":287,"d":3.14,"hello":"Hello World","arr":[1,2,3]})";
  auto s = glz::read_json<my_struct>(buffer);
}
$ g++ --version
g++ (GCC) 12.2.1 20221121 (Red Hat 12.2.1-4)
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ clang++ --version
clang version 14.0.5 (Fedora 14.0.5-2.fc36)
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ g++ -std=c++20 -I /usr/local/include/glaze -fsanitize=address example.cc && ./a.out 
=================================================================
==3878334==ERROR: AddressSanitizer: global-buffer-overflow on address 0x00000042d040 at pc 0x00000040521a bp 0x7ffcd7ec8540 sp 0x7ffcd7ec8538
READ of size 8 at 0x00000042d040 thread T0
    #0 0x405219 in glz::to_uint64(char const*, unsigned long) (/tmp/a.out+0x405219)
    #1 0x411fba in bool glz::string_cmp<std::basic_string_view<char, std::char_traits<char> > const&, std::basic_string_view<char, std::char_traits<char> >&>(std::basic_string_view<char, std::char_traits<char> > const&, std::basic_string_view<char, std::char_traits<char> >&) (/tmp/a.out+0x411fba)
    #2 0x40eda6 in decltype(auto) glz::detail::single_char_map<std::variant<int my_struct::*, double my_struct::*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > my_struct::*, std::array<unsigned long, 3ul> my_struct::*>, glz::detail::single_char_hash_desc{4ul, true, (unsigned char)1, (unsigned char)97, (unsigned char)105, true}>::at<std::basic_string_view<char, std::char_traits<char> >&>(std::basic_string_view<char, std::char_traits<char> >&) const (/tmp/a.out+0x40eda6)
    #3 0x40f5bd in void glz::detail::from_json<my_struct>::op<glz::opts{10u, false, true, true, false, false, false, (char)32, (unsigned char)3}, char*&, my_struct, glz::context&, char*&>(my_struct&, glz::context&, char*&, char*&) (/tmp/a.out+0x40f5bd)
    #4 0x40cdbc in void glz::detail::read<10u>::op<glz::opts{10u, false, true, true, false, false, false, (char)32, (unsigned char)3}, my_struct&, glz::context&, char*&, char*&>(my_struct&, glz::context&, char*&, char*&) (/tmp/a.out+0x40cdbc)
    #5 0x409d8b in void glz::read<glz::opts{10u, false, true, true, false, false, false, (char)32, (unsigned char)3}, my_struct, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, glz::context&>(my_struct&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, glz::context&) (/tmp/a.out+0x409d8b)
    #6 0x407586 in auto glz::read_json<my_struct, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) (/tmp/a.out+0x407586)
    #7 0x404703 in main (/tmp/a.out+0x404703)
    #8 0x7f2fa982950f in __libc_start_call_main (/lib64/libc.so.6+0x2950f)
    #9 0x7f2fa98295c8 in __libc_start_main_impl (/lib64/libc.so.6+0x295c8)
    #10 0x4044b4 in _start (/tmp/a.out+0x4044b4)

0x00000042d042 is located 0 bytes to the right of global variable '*.LC55' defined in 'example.cc' (0x42d040) of size 2
  '*.LC55' is ascii string 'i'
SUMMARY: AddressSanitizer: global-buffer-overflow (/tmp/a.out+0x405219) in glz::to_uint64(char const*, unsigned long)
Shadow bytes around the buggy address:
  0x00008007d9b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x00008007d9c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x00008007d9d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x00008007d9e0: 00 00 00 00 00 00 06 f9 f9 f9 f9 f9 00 00 00 00
  0x00008007d9f0: 00 00 00 00 00 00 00 00 00 00 01 f9 f9 f9 f9 f9
=>0x00008007da00: 00 00 f9 f9 f9 f9 f9 f9[02]f9 f9 f9 f9 f9 f9 f9
  0x00008007da10: 02 f9 f9 f9 f9 f9 f9 f9 06 f9 f9 f9 f9 f9 f9 f9
  0x00008007da20: 04 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 00 00 00 00
  0x00008007da30: 00 00 00 00 00 00 00 00 00 00 f9 f9 f9 f9 f9 f9
  0x00008007da40: 00 04 f9 f9 f9 f9 f9 f9 00 00 00 00 00 00 00 00
  0x00008007da50: 00 00 00 00 00 03 f9 f9 f9 f9 f9 f9 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==3878334==ABORTING
$ 

Version used:

$ git rev-parse HEAD
99ce9aa2649585541c499faff8b2b81b9599c227

Also the version number in CMakeLists.txt does not seem to be correct (0.2.4), both in main branch and the latest release, which is labeled 0.2.9.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.