Json: "Custom data source" exemple make no sense

Created on 6 Oct 2020  路  2Comments  路  Source: nlohmann/json

"_Custom data source_" form readme exemple make no sense and does not compile (?)

  1. copy exemple
  2. paste
  3. compile

Some _(I think are)_ problems:

  1. MyIterator begin(MyContainer& tgt) { return MyIterator{&tgt}; } does not compile, stop some complaining only if MyContainer& tgt is const (const MyContainer& tgt) but this make it useless
  1. reference operator*() const {return target.get_current(); } but target is a pointer (also null)

  2. MyIterator& operator++() {MyContainer.advance(); return *this; } what is supposed to be MyContainer.advance(); static? reference? pointer?

Tennsy 4 (Arduino)

Platformio on mac osx,
gcc-arm-embedded: 5.4.1
build_flags =
-std=c++17
-lstdc++
-lnosys
-fno-exceptions

  • [x] latest release version 3.9.1 single header version
  • [x] the develop branch single header version

ERROR LIST:

src/main.cpp:243:27:   required from here
lib/json.hpp:23225:37: error: no matching function for call to 'input_adapter(MyContainer&)'
         parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions, ignore_comments).parse(true, result);
src/main.cpp:243:27:   required from here
lib/json.hpp:5164:83: error: binding 'const MyContainer' to reference of type 'MyContainer&' discards qualifiers
 auto input_adapter(const ContainerType& container) -> decltype(input_adapter(begin(container), end(container)))



md5-1d838189b6493d9915d748fb63421854



lib/json.hpp:5299:32: note:   template argument deduction/substitution failed:
lib/json.hpp:5198:30: error: no type named 'type' in 'struct std::enable_if<false, int>'
                int >::type = 0 >



md5-1d838189b6493d9915d748fb63421854



src/main.cpp: In member function 'MyIterator& MyIterator::operator++()':
src/main.cpp:218:20: error: expected unqualified-id before '.' token
         MyContainer.advance();



md5-1d838189b6493d9915d748fb63421854



src/main.cpp: In member function 'const char& MyIterator::operator*() const':
src/main.cpp:227:23: error: request for member 'get_current' in '((const MyIterator*)this)->MyIterator::target', which is of pointer type 'MyContainer* const' (maybe you meant to use '->' ?)
         return target.get_current();

Thanks in advance,
Luca

bug needs more info

All 2 comments

  • Can you compile the test suite?
  • Can you share more code, like src/main.cpp?

O bhai

Was this page helpful?
0 / 5 - 0 ratings

Related issues

afowles picture afowles  路  3Comments

sqwunkly picture sqwunkly  路  3Comments

zhishupp picture zhishupp  路  4Comments

alienzj picture alienzj  路  4Comments

jmlemetayer picture jmlemetayer  路  3Comments