Giter Club home page Giter Club logo

glaze's Issues

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
   );

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';
}

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.

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)

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");
    
}

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";
      |                                           ^
$ 

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;
}

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;

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
}]

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?

String deduplication?

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

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);

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).

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

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.

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.

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!

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)

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)

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

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?

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.

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.

$ 

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
$

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.

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.

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");

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?

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.