reverse iterators

This commit is contained in:
Niels 2015-02-14 16:47:14 +01:00
parent d87e770767
commit cc4a8319a1
4 changed files with 1216 additions and 314 deletions

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
.deps .deps
utf8_test utf8_test
json_unit

View file

@ -93,7 +93,10 @@ class basic_json
using iterator = basic_json::iterator; using iterator = basic_json::iterator;
/// a const iterator for a basic_json container /// a const iterator for a basic_json container
using const_iterator = basic_json::const_iterator; using const_iterator = basic_json::const_iterator;
/// a reverse iterator for a basic_json container
using reverse_iterator = std::reverse_iterator<iterator>;
/// a const reverse iterator for a basic_json container
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
/////////////////////////// ///////////////////////////
// JSON value data types // // JSON value data types //
@ -264,6 +267,8 @@ class basic_json
std::enable_if< std::enable_if<
not std::is_same<V, basic_json::iterator>::value and not std::is_same<V, basic_json::iterator>::value and
not std::is_same<V, basic_json::const_iterator>::value and not std::is_same<V, basic_json::const_iterator>::value and
not std::is_same<V, basic_json::reverse_iterator>::value and
not std::is_same<V, basic_json::const_reverse_iterator>::value and
not std::is_same<V, typename array_t::iterator>::value and not std::is_same<V, typename array_t::iterator>::value and
not std::is_same<V, typename array_t::const_iterator>::value and not std::is_same<V, typename array_t::const_iterator>::value and
std::is_constructible<basic_json, typename V::value_type>::value, int>::type std::is_constructible<basic_json, typename V::value_type>::value, int>::type
@ -822,6 +827,30 @@ class basic_json
return result; return result;
} }
/// returns a reverse iterator to the beginning
inline reverse_iterator rbegin() noexcept
{
return reverse_iterator(end());
}
/// returns a reverse iterator to the end
inline reverse_iterator rend() noexcept
{
return reverse_iterator(begin());
}
/// returns a reverse iterator to the beginning
inline const_reverse_iterator crbegin() const noexcept
{
return const_reverse_iterator(cend());
}
/// returns a reverse iterator to the end
inline const_reverse_iterator crend() const noexcept
{
return const_reverse_iterator(cbegin());
}
////////////// //////////////
// capacity // // capacity //
@ -2494,7 +2523,8 @@ class basic_json
{ {
char yych; char yych;
unsigned int yyaccept = 0; unsigned int yyaccept = 0;
static const unsigned char yybm[] = { static const unsigned char yybm[] =
{
0, 64, 64, 64, 64, 64, 64, 64, 0, 64, 64, 64, 64, 64, 64, 64,
64, 96, 96, 64, 64, 96, 64, 64, 64, 96, 96, 64, 64, 96, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
@ -2530,55 +2560,132 @@ class basic_json
}; };
yych = *m_cursor; yych = *m_cursor;
if (yych <= '9') { if (yych <= '9')
if (yych <= ' ') { {
if (yych <= '\n') { if (yych <= ' ')
if (yych <= 0x00) goto json_parser_27; {
if (yych <= 0x08) goto json_parser_29; if (yych <= '\n')
if (yych <= '\t') goto json_parser_3; {
goto json_parser_4; if (yych <= 0x00)
} else { {
if (yych == '\r') goto json_parser_3; goto json_parser_27;
if (yych <= 0x1F) goto json_parser_29; }
if (yych <= 0x08)
{
goto json_parser_29;
}
if (yych <= '\t')
{
goto json_parser_3; goto json_parser_3;
} }
} else { goto json_parser_4;
if (yych <= ',') { }
if (yych == '"') goto json_parser_26; else
if (yych <= '+') goto json_parser_29; {
if (yych == '\r')
{
goto json_parser_3;
}
if (yych <= 0x1F)
{
goto json_parser_29;
}
goto json_parser_3;
}
}
else
{
if (yych <= ',')
{
if (yych == '"')
{
goto json_parser_26;
}
if (yych <= '+')
{
goto json_parser_29;
}
goto json_parser_14; goto json_parser_14;
} else { }
if (yych <= '-') goto json_parser_22; else
if (yych <= '/') goto json_parser_29; {
if (yych <= '0') goto json_parser_23; if (yych <= '-')
{
goto json_parser_22;
}
if (yych <= '/')
{
goto json_parser_29;
}
if (yych <= '0')
{
goto json_parser_23;
}
goto json_parser_25; goto json_parser_25;
} }
} }
} else { }
if (yych <= 'm') { else
if (yych <= '\\') { {
if (yych <= ':') goto json_parser_16; if (yych <= 'm')
if (yych == '[') goto json_parser_6; {
goto json_parser_29; if (yych <= '\\')
} else { {
if (yych <= ']') goto json_parser_8; if (yych <= ':')
if (yych == 'f') goto json_parser_21; {
goto json_parser_16;
}
if (yych == '[')
{
goto json_parser_6;
}
goto json_parser_29; goto json_parser_29;
} }
} else { else
if (yych <= 'z') { {
if (yych <= 'n') goto json_parser_18; if (yych <= ']')
if (yych == 't') goto json_parser_20; {
goto json_parser_8;
}
if (yych == 'f')
{
goto json_parser_21;
}
goto json_parser_29; goto json_parser_29;
} else { }
if (yych <= '{') goto json_parser_10; }
if (yych == '}') goto json_parser_12; else
{
if (yych <= 'z')
{
if (yych <= 'n')
{
goto json_parser_18;
}
if (yych == 't')
{
goto json_parser_20;
}
goto json_parser_29;
}
else
{
if (yych <= '{')
{
goto json_parser_10;
}
if (yych == '}')
{
goto json_parser_12;
}
goto json_parser_29; goto json_parser_29;
} }
} }
} }
json_parser_2: json_parser_2:
{ return scan(); } {
return scan();
}
json_parser_3: json_parser_3:
yych = *++m_cursor; yych = *++m_cursor;
goto json_parser_5; goto json_parser_5;
@ -2586,61 +2693,108 @@ json_parser_4:
++m_cursor; ++m_cursor;
yych = *m_cursor; yych = *m_cursor;
json_parser_5: json_parser_5:
if (yybm[0+yych] & 32) { if (yybm[0 + yych] & 32)
{
goto json_parser_4; goto json_parser_4;
} }
goto json_parser_2; goto json_parser_2;
json_parser_6: json_parser_6:
++m_cursor; ++m_cursor;
{ return token_type::begin_array; } {
return token_type::begin_array;
}
json_parser_8: json_parser_8:
++m_cursor; ++m_cursor;
{ return token_type::end_array; } {
return token_type::end_array;
}
json_parser_10: json_parser_10:
++m_cursor; ++m_cursor;
{ return token_type::begin_object; } {
return token_type::begin_object;
}
json_parser_12: json_parser_12:
++m_cursor; ++m_cursor;
{ return token_type::end_object; } {
return token_type::end_object;
}
json_parser_14: json_parser_14:
++m_cursor; ++m_cursor;
{ return token_type::value_separator; } {
return token_type::value_separator;
}
json_parser_16: json_parser_16:
++m_cursor; ++m_cursor;
{ return token_type::name_separator; } {
return token_type::name_separator;
}
json_parser_18: json_parser_18:
yyaccept = 0; yyaccept = 0;
yych = *(m_marker = ++m_cursor); yych = *(m_marker = ++m_cursor);
if (yych == 'u') goto json_parser_59; if (yych == 'u')
{
goto json_parser_59;
}
json_parser_19: json_parser_19:
{ return token_type::parse_error; } {
return token_type::parse_error;
}
json_parser_20: json_parser_20:
yyaccept = 0; yyaccept = 0;
yych = *(m_marker = ++m_cursor); yych = *(m_marker = ++m_cursor);
if (yych == 'r') goto json_parser_55; if (yych == 'r')
{
goto json_parser_55;
}
goto json_parser_19; goto json_parser_19;
json_parser_21: json_parser_21:
yyaccept = 0; yyaccept = 0;
yych = *(m_marker = ++m_cursor); yych = *(m_marker = ++m_cursor);
if (yych == 'a') goto json_parser_50; if (yych == 'a')
{
goto json_parser_50;
}
goto json_parser_19; goto json_parser_19;
json_parser_22: json_parser_22:
yych = *++m_cursor; yych = *++m_cursor;
if (yych <= '/') goto json_parser_19; if (yych <= '/')
if (yych <= '0') goto json_parser_49; {
if (yych <= '9') goto json_parser_40; goto json_parser_19;
}
if (yych <= '0')
{
goto json_parser_49;
}
if (yych <= '9')
{
goto json_parser_40;
}
goto json_parser_19; goto json_parser_19;
json_parser_23: json_parser_23:
yyaccept = 1; yyaccept = 1;
yych = *(m_marker = ++m_cursor); yych = *(m_marker = ++m_cursor);
if (yych <= 'D') { if (yych <= 'D')
if (yych == '.') goto json_parser_42; {
} else { if (yych == '.')
if (yych <= 'E') goto json_parser_43; {
if (yych == 'e') goto json_parser_43; goto json_parser_42;
}
}
else
{
if (yych <= 'E')
{
goto json_parser_43;
}
if (yych == 'e')
{
goto json_parser_43;
}
} }
json_parser_24: json_parser_24:
{ return token_type::value_number; } {
return token_type::value_number;
}
json_parser_25: json_parser_25:
yyaccept = 1; yyaccept = 1;
yych = *(m_marker = ++m_cursor); yych = *(m_marker = ++m_cursor);
@ -2648,11 +2802,16 @@ json_parser_25:
json_parser_26: json_parser_26:
yyaccept = 0; yyaccept = 0;
yych = *(m_marker = ++m_cursor); yych = *(m_marker = ++m_cursor);
if (yych <= 0x00) goto json_parser_19; if (yych <= 0x00)
{
goto json_parser_19;
}
goto json_parser_31; goto json_parser_31;
json_parser_27: json_parser_27:
++m_cursor; ++m_cursor;
{ return token_type::end_of_input; } {
return token_type::end_of_input;
}
json_parser_29: json_parser_29:
yych = *++m_cursor; yych = *++m_cursor;
goto json_parser_19; goto json_parser_19;
@ -2660,99 +2819,225 @@ json_parser_30:
++m_cursor; ++m_cursor;
yych = *m_cursor; yych = *m_cursor;
json_parser_31: json_parser_31:
if (yybm[0+yych] & 64) { if (yybm[0 + yych] & 64)
{
goto json_parser_30; goto json_parser_30;
} }
if (yych <= 0x00) goto json_parser_32; if (yych <= 0x00)
if (yych <= '"') goto json_parser_34; {
goto json_parser_32;
}
if (yych <= '"')
{
goto json_parser_34;
}
goto json_parser_33; goto json_parser_33;
json_parser_32: json_parser_32:
m_cursor = m_marker; m_cursor = m_marker;
if (yyaccept == 0) { if (yyaccept == 0)
{
goto json_parser_19; goto json_parser_19;
} else { }
else
{
goto json_parser_24; goto json_parser_24;
} }
json_parser_33: json_parser_33:
++m_cursor; ++m_cursor;
yych = *m_cursor; yych = *m_cursor;
if (yych <= 'e') { if (yych <= 'e')
if (yych <= '/') { {
if (yych == '"') goto json_parser_30; if (yych <= '/')
if (yych <= '.') goto json_parser_32; {
if (yych == '"')
{
goto json_parser_30; goto json_parser_30;
} else { }
if (yych <= '\\') { if (yych <= '.')
if (yych <= '[') goto json_parser_32; {
goto json_parser_32;
}
goto json_parser_30; goto json_parser_30;
} else { }
if (yych == 'b') goto json_parser_30; else
{
if (yych <= '\\')
{
if (yych <= '[')
{
goto json_parser_32;
}
goto json_parser_30;
}
else
{
if (yych == 'b')
{
goto json_parser_30;
}
goto json_parser_32; goto json_parser_32;
} }
} }
} else { }
if (yych <= 'q') { else
if (yych <= 'f') goto json_parser_30; {
if (yych == 'n') goto json_parser_30; if (yych <= 'q')
{
if (yych <= 'f')
{
goto json_parser_30;
}
if (yych == 'n')
{
goto json_parser_30;
}
goto json_parser_32; goto json_parser_32;
} else { }
if (yych <= 's') { else
if (yych <= 'r') goto json_parser_30; {
if (yych <= 's')
{
if (yych <= 'r')
{
goto json_parser_30;
}
goto json_parser_32; goto json_parser_32;
} else { }
if (yych <= 't') goto json_parser_30; else
if (yych <= 'u') goto json_parser_36; {
if (yych <= 't')
{
goto json_parser_30;
}
if (yych <= 'u')
{
goto json_parser_36;
}
goto json_parser_32; goto json_parser_32;
} }
} }
} }
json_parser_34: json_parser_34:
++m_cursor; ++m_cursor;
{ return token_type::value_string; } {
return token_type::value_string;
}
json_parser_36: json_parser_36:
++m_cursor; ++m_cursor;
yych = *m_cursor; yych = *m_cursor;
if (yych <= '@') { if (yych <= '@')
if (yych <= '/') goto json_parser_32; {
if (yych >= ':') goto json_parser_32; if (yych <= '/')
} else { {
if (yych <= 'F') goto json_parser_37; goto json_parser_32;
if (yych <= '`') goto json_parser_32; }
if (yych >= 'g') goto json_parser_32; if (yych >= ':')
{
goto json_parser_32;
}
}
else
{
if (yych <= 'F')
{
goto json_parser_37;
}
if (yych <= '`')
{
goto json_parser_32;
}
if (yych >= 'g')
{
goto json_parser_32;
}
} }
json_parser_37: json_parser_37:
++m_cursor; ++m_cursor;
yych = *m_cursor; yych = *m_cursor;
if (yych <= '@') { if (yych <= '@')
if (yych <= '/') goto json_parser_32; {
if (yych >= ':') goto json_parser_32; if (yych <= '/')
} else { {
if (yych <= 'F') goto json_parser_38; goto json_parser_32;
if (yych <= '`') goto json_parser_32; }
if (yych >= 'g') goto json_parser_32; if (yych >= ':')
{
goto json_parser_32;
}
}
else
{
if (yych <= 'F')
{
goto json_parser_38;
}
if (yych <= '`')
{
goto json_parser_32;
}
if (yych >= 'g')
{
goto json_parser_32;
}
} }
json_parser_38: json_parser_38:
++m_cursor; ++m_cursor;
yych = *m_cursor; yych = *m_cursor;
if (yych <= '@') { if (yych <= '@')
if (yych <= '/') goto json_parser_32; {
if (yych >= ':') goto json_parser_32; if (yych <= '/')
} else { {
if (yych <= 'F') goto json_parser_39; goto json_parser_32;
if (yych <= '`') goto json_parser_32; }
if (yych >= 'g') goto json_parser_32; if (yych >= ':')
{
goto json_parser_32;
}
}
else
{
if (yych <= 'F')
{
goto json_parser_39;
}
if (yych <= '`')
{
goto json_parser_32;
}
if (yych >= 'g')
{
goto json_parser_32;
}
} }
json_parser_39: json_parser_39:
++m_cursor; ++m_cursor;
yych = *m_cursor; yych = *m_cursor;
if (yych <= '@') { if (yych <= '@')
if (yych <= '/') goto json_parser_32; {
if (yych <= '9') goto json_parser_30; if (yych <= '/')
{
goto json_parser_32; goto json_parser_32;
} else { }
if (yych <= 'F') goto json_parser_30; if (yych <= '9')
if (yych <= '`') goto json_parser_32; {
if (yych <= 'f') goto json_parser_30; goto json_parser_30;
}
goto json_parser_32;
}
else
{
if (yych <= 'F')
{
goto json_parser_30;
}
if (yych <= '`')
{
goto json_parser_32;
}
if (yych <= 'f')
{
goto json_parser_30;
}
goto json_parser_32; goto json_parser_32;
} }
json_parser_40: json_parser_40:
@ -2760,88 +3045,188 @@ json_parser_40:
m_marker = ++m_cursor; m_marker = ++m_cursor;
yych = *m_cursor; yych = *m_cursor;
json_parser_41: json_parser_41:
if (yybm[0+yych] & 128) { if (yybm[0 + yych] & 128)
{
goto json_parser_40; goto json_parser_40;
} }
if (yych <= 'D') { if (yych <= 'D')
if (yych != '.') goto json_parser_24; {
} else { if (yych != '.')
if (yych <= 'E') goto json_parser_43; {
if (yych == 'e') goto json_parser_43; goto json_parser_24;
}
}
else
{
if (yych <= 'E')
{
goto json_parser_43;
}
if (yych == 'e')
{
goto json_parser_43;
}
goto json_parser_24; goto json_parser_24;
} }
json_parser_42: json_parser_42:
yych = *++m_cursor; yych = *++m_cursor;
if (yych <= '/') goto json_parser_32; if (yych <= '/')
if (yych <= '9') goto json_parser_47; {
goto json_parser_32;
}
if (yych <= '9')
{
goto json_parser_47;
}
goto json_parser_32; goto json_parser_32;
json_parser_43: json_parser_43:
yych = *++m_cursor; yych = *++m_cursor;
if (yych <= ',') { if (yych <= ',')
if (yych != '+') goto json_parser_32; {
} else { if (yych != '+')
if (yych <= '-') goto json_parser_44; {
if (yych <= '/') goto json_parser_32; goto json_parser_32;
if (yych <= '9') goto json_parser_45; }
}
else
{
if (yych <= '-')
{
goto json_parser_44;
}
if (yych <= '/')
{
goto json_parser_32;
}
if (yych <= '9')
{
goto json_parser_45;
}
goto json_parser_32; goto json_parser_32;
} }
json_parser_44: json_parser_44:
yych = *++m_cursor; yych = *++m_cursor;
if (yych <= '/') goto json_parser_32; if (yych <= '/')
if (yych >= ':') goto json_parser_32; {
goto json_parser_32;
}
if (yych >= ':')
{
goto json_parser_32;
}
json_parser_45: json_parser_45:
++m_cursor; ++m_cursor;
yych = *m_cursor; yych = *m_cursor;
if (yych <= '/') goto json_parser_24; if (yych <= '/')
if (yych <= '9') goto json_parser_45; {
goto json_parser_24;
}
if (yych <= '9')
{
goto json_parser_45;
}
goto json_parser_24; goto json_parser_24;
json_parser_47: json_parser_47:
yyaccept = 1; yyaccept = 1;
m_marker = ++m_cursor; m_marker = ++m_cursor;
yych = *m_cursor; yych = *m_cursor;
if (yych <= 'D') { if (yych <= 'D')
if (yych <= '/') goto json_parser_24; {
if (yych <= '9') goto json_parser_47; if (yych <= '/')
{
goto json_parser_24; goto json_parser_24;
} else { }
if (yych <= 'E') goto json_parser_43; if (yych <= '9')
if (yych == 'e') goto json_parser_43; {
goto json_parser_47;
}
goto json_parser_24;
}
else
{
if (yych <= 'E')
{
goto json_parser_43;
}
if (yych == 'e')
{
goto json_parser_43;
}
goto json_parser_24; goto json_parser_24;
} }
json_parser_49: json_parser_49:
yyaccept = 1; yyaccept = 1;
yych = *(m_marker = ++m_cursor); yych = *(m_marker = ++m_cursor);
if (yych <= 'D') { if (yych <= 'D')
if (yych == '.') goto json_parser_42; {
if (yych == '.')
{
goto json_parser_42;
}
goto json_parser_24; goto json_parser_24;
} else { }
if (yych <= 'E') goto json_parser_43; else
if (yych == 'e') goto json_parser_43; {
if (yych <= 'E')
{
goto json_parser_43;
}
if (yych == 'e')
{
goto json_parser_43;
}
goto json_parser_24; goto json_parser_24;
} }
json_parser_50: json_parser_50:
yych = *++m_cursor; yych = *++m_cursor;
if (yych != 'l') goto json_parser_32; if (yych != 'l')
{
goto json_parser_32;
}
yych = *++m_cursor; yych = *++m_cursor;
if (yych != 's') goto json_parser_32; if (yych != 's')
{
goto json_parser_32;
}
yych = *++m_cursor; yych = *++m_cursor;
if (yych != 'e') goto json_parser_32; if (yych != 'e')
{
goto json_parser_32;
}
++m_cursor; ++m_cursor;
{ return token_type::literal_false; } {
return token_type::literal_false;
}
json_parser_55: json_parser_55:
yych = *++m_cursor; yych = *++m_cursor;
if (yych != 'u') goto json_parser_32; if (yych != 'u')
{
goto json_parser_32;
}
yych = *++m_cursor; yych = *++m_cursor;
if (yych != 'e') goto json_parser_32; if (yych != 'e')
{
goto json_parser_32;
}
++m_cursor; ++m_cursor;
{ return token_type::literal_true; } {
return token_type::literal_true;
}
json_parser_59: json_parser_59:
yych = *++m_cursor; yych = *++m_cursor;
if (yych != 'l') goto json_parser_32; if (yych != 'l')
{
goto json_parser_32;
}
yych = *++m_cursor; yych = *++m_cursor;
if (yych != 'l') goto json_parser_32; if (yych != 'l')
{
goto json_parser_32;
}
++m_cursor; ++m_cursor;
{ return token_type::literal_null; } {
return token_type::literal_null;
}
} }
} }

View file

@ -93,7 +93,10 @@ class basic_json
using iterator = basic_json::iterator; using iterator = basic_json::iterator;
/// a const iterator for a basic_json container /// a const iterator for a basic_json container
using const_iterator = basic_json::const_iterator; using const_iterator = basic_json::const_iterator;
/// a reverse iterator for a basic_json container
using reverse_iterator = std::reverse_iterator<iterator>;
/// a const reverse iterator for a basic_json container
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
/////////////////////////// ///////////////////////////
// JSON value data types // // JSON value data types //
@ -264,6 +267,8 @@ class basic_json
std::enable_if< std::enable_if<
not std::is_same<V, basic_json::iterator>::value and not std::is_same<V, basic_json::iterator>::value and
not std::is_same<V, basic_json::const_iterator>::value and not std::is_same<V, basic_json::const_iterator>::value and
not std::is_same<V, basic_json::reverse_iterator>::value and
not std::is_same<V, basic_json::const_reverse_iterator>::value and
not std::is_same<V, typename array_t::iterator>::value and not std::is_same<V, typename array_t::iterator>::value and
not std::is_same<V, typename array_t::const_iterator>::value and not std::is_same<V, typename array_t::const_iterator>::value and
std::is_constructible<basic_json, typename V::value_type>::value, int>::type std::is_constructible<basic_json, typename V::value_type>::value, int>::type
@ -822,6 +827,30 @@ class basic_json
return result; return result;
} }
/// returns a reverse iterator to the beginning
inline reverse_iterator rbegin() noexcept
{
return reverse_iterator(end());
}
/// returns a reverse iterator to the end
inline reverse_iterator rend() noexcept
{
return reverse_iterator(begin());
}
/// returns a reverse iterator to the beginning
inline const_reverse_iterator crbegin() const noexcept
{
return const_reverse_iterator(cend());
}
/// returns a reverse iterator to the end
inline const_reverse_iterator crend() const noexcept
{
return const_reverse_iterator(cbegin());
}
////////////// //////////////
// capacity // // capacity //

View file

@ -2420,6 +2420,81 @@ TEST_CASE("iterators")
CHECK(it != j_const.cend()); CHECK(it != j_const.cend());
CHECK(*it == j_const); CHECK(*it == j_const);
} }
SECTION("json + rbegin/rend")
{
json::reverse_iterator it = j.rbegin();
CHECK(it != j.rend());
CHECK(*it == j);
it++;
CHECK(it != j.rbegin());
CHECK(it == j.rend());
it--;
CHECK(it == j.rbegin());
CHECK(it != j.rend());
CHECK(*it == j);
++it;
CHECK(it != j.rbegin());
CHECK(it == j.rend());
--it;
CHECK(it == j.rbegin());
CHECK(it != j.rend());
CHECK(*it == j);
}
SECTION("json + crbegin/crend")
{
json::const_reverse_iterator it = j.crbegin();
CHECK(it != j.crend());
CHECK(*it == j);
it++;
CHECK(it != j.crbegin());
CHECK(it == j.crend());
it--;
CHECK(it == j.crbegin());
CHECK(it != j.crend());
CHECK(*it == j);
++it;
CHECK(it != j.crbegin());
CHECK(it == j.crend());
--it;
CHECK(it == j.crbegin());
CHECK(it != j.crend());
CHECK(*it == j);
}
SECTION("const json + crbegin/crend")
{
json::const_reverse_iterator it = j_const.crbegin();
CHECK(it != j_const.crend());
CHECK(*it == j_const);
it++;
CHECK(it != j_const.crbegin());
CHECK(it == j_const.crend());
it--;
CHECK(it == j_const.crbegin());
CHECK(it != j_const.crend());
CHECK(*it == j_const);
++it;
CHECK(it != j_const.crbegin());
CHECK(it == j_const.crend());
--it;
CHECK(it == j_const.crbegin());
CHECK(it != j_const.crend());
CHECK(*it == j_const);
}
} }
SECTION("string") SECTION("string")
@ -2526,6 +2601,81 @@ TEST_CASE("iterators")
CHECK(it != j_const.cend()); CHECK(it != j_const.cend());
CHECK(*it == j_const); CHECK(*it == j_const);
} }
SECTION("json + rbegin/rend")
{
json::reverse_iterator it = j.rbegin();
CHECK(it != j.rend());
CHECK(*it == j);
it++;
CHECK(it != j.rbegin());
CHECK(it == j.rend());
it--;
CHECK(it == j.rbegin());
CHECK(it != j.rend());
CHECK(*it == j);
++it;
CHECK(it != j.rbegin());
CHECK(it == j.rend());
--it;
CHECK(it == j.rbegin());
CHECK(it != j.rend());
CHECK(*it == j);
}
SECTION("json + crbegin/crend")
{
json::const_reverse_iterator it = j.crbegin();
CHECK(it != j.crend());
CHECK(*it == j);
it++;
CHECK(it != j.crbegin());
CHECK(it == j.crend());
it--;
CHECK(it == j.crbegin());
CHECK(it != j.crend());
CHECK(*it == j);
++it;
CHECK(it != j.crbegin());
CHECK(it == j.crend());
--it;
CHECK(it == j.crbegin());
CHECK(it != j.crend());
CHECK(*it == j);
}
SECTION("const json + crbegin/crend")
{
json::const_reverse_iterator it = j_const.crbegin();
CHECK(it != j_const.crend());
CHECK(*it == j_const);
it++;
CHECK(it != j_const.crbegin());
CHECK(it == j_const.crend());
it--;
CHECK(it == j_const.crbegin());
CHECK(it != j_const.crend());
CHECK(*it == j_const);
++it;
CHECK(it != j_const.crbegin());
CHECK(it == j_const.crend());
--it;
CHECK(it == j_const.crbegin());
CHECK(it != j_const.crend());
CHECK(*it == j_const);
}
} }
SECTION("array") SECTION("array")
@ -2540,14 +2690,17 @@ TEST_CASE("iterators")
auto it = it_begin; auto it = it_begin;
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j[0]);
it++; it++;
CHECK(it != it_begin); CHECK(it != it_begin);
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j[1]);
++it; ++it;
CHECK(it != it_begin); CHECK(it != it_begin);
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j[2]);
++it; ++it;
CHECK(it != it_begin); CHECK(it != it_begin);
@ -2561,14 +2714,17 @@ TEST_CASE("iterators")
auto it = it_begin; auto it = it_begin;
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j_const[0]);
it++; it++;
CHECK(it != it_begin); CHECK(it != it_begin);
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j_const[1]);
++it; ++it;
CHECK(it != it_begin); CHECK(it != it_begin);
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j_const[2]);
++it; ++it;
CHECK(it != it_begin); CHECK(it != it_begin);
@ -2582,14 +2738,17 @@ TEST_CASE("iterators")
auto it = it_begin; auto it = it_begin;
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j[0]);
it++; it++;
CHECK(it != it_begin); CHECK(it != it_begin);
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j[1]);
++it; ++it;
CHECK(it != it_begin); CHECK(it != it_begin);
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j[2]);
++it; ++it;
CHECK(it != it_begin); CHECK(it != it_begin);
@ -2598,19 +2757,94 @@ TEST_CASE("iterators")
SECTION("const json + cbegin/cend") SECTION("const json + cbegin/cend")
{ {
json::const_iterator it_begin = j.cbegin(); json::const_iterator it_begin = j_const.cbegin();
json::const_iterator it_end = j.cend(); json::const_iterator it_end = j_const.cend();
auto it = it_begin; auto it = it_begin;
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j[0]);
it++; it++;
CHECK(it != it_begin); CHECK(it != it_begin);
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j[1]);
++it; ++it;
CHECK(it != it_begin); CHECK(it != it_begin);
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j[2]);
++it;
CHECK(it != it_begin);
CHECK(it == it_end);
}
SECTION("json + rbegin/rend")
{
json::reverse_iterator it_begin = j.rbegin();
json::reverse_iterator it_end = j.rend();
auto it = it_begin;
CHECK(it != it_end);
CHECK(*it == j[2]);
it++;
CHECK(it != it_begin);
CHECK(it != it_end);
CHECK(*it == j[1]);
++it;
CHECK(it != it_begin);
CHECK(it != it_end);
CHECK(*it == j[0]);
++it;
CHECK(it != it_begin);
CHECK(it == it_end);
}
SECTION("json + crbegin/crend")
{
json::const_reverse_iterator it_begin = j.crbegin();
json::const_reverse_iterator it_end = j.crend();
auto it = it_begin;
CHECK(it != it_end);
CHECK(*it == j[2]);
it++;
CHECK(it != it_begin);
CHECK(it != it_end);
CHECK(*it == j[1]);
++it;
CHECK(it != it_begin);
CHECK(it != it_end);
CHECK(*it == j[0]);
++it;
CHECK(it != it_begin);
CHECK(it == it_end);
}
SECTION("const json + crbegin/crend")
{
json::const_reverse_iterator it_begin = j_const.crbegin();
json::const_reverse_iterator it_end = j_const.crend();
auto it = it_begin;
CHECK(it != it_end);
CHECK(*it == j[2]);
it++;
CHECK(it != it_begin);
CHECK(it != it_end);
CHECK(*it == j[1]);
++it;
CHECK(it != it_begin);
CHECK(it != it_end);
CHECK(*it == j[0]);
++it; ++it;
CHECK(it != it_begin); CHECK(it != it_begin);
@ -2620,7 +2854,7 @@ TEST_CASE("iterators")
SECTION("object") SECTION("object")
{ {
json j = {{"one", 1}, {"two", 2}, {"three", 3}}; json j = {{"A", 1}, {"B", 2}, {"C", 3}};
json j_const(j); json j_const(j);
SECTION("json + begin/end") SECTION("json + begin/end")
@ -2630,14 +2864,17 @@ TEST_CASE("iterators")
auto it = it_begin; auto it = it_begin;
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j["A"]);
it++; it++;
CHECK(it != it_begin); CHECK(it != it_begin);
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j["B"]);
++it; ++it;
CHECK(it != it_begin); CHECK(it != it_begin);
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j["C"]);
++it; ++it;
CHECK(it != it_begin); CHECK(it != it_begin);
@ -2651,14 +2888,17 @@ TEST_CASE("iterators")
auto it = it_begin; auto it = it_begin;
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j_const["A"]);
it++; it++;
CHECK(it != it_begin); CHECK(it != it_begin);
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j_const["B"]);
++it; ++it;
CHECK(it != it_begin); CHECK(it != it_begin);
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j_const["C"]);
++it; ++it;
CHECK(it != it_begin); CHECK(it != it_begin);
@ -2672,14 +2912,17 @@ TEST_CASE("iterators")
auto it = it_begin; auto it = it_begin;
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j["A"]);
it++; it++;
CHECK(it != it_begin); CHECK(it != it_begin);
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j["B"]);
++it; ++it;
CHECK(it != it_begin); CHECK(it != it_begin);
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j["C"]);
++it; ++it;
CHECK(it != it_begin); CHECK(it != it_begin);
@ -2688,19 +2931,94 @@ TEST_CASE("iterators")
SECTION("const json + cbegin/cend") SECTION("const json + cbegin/cend")
{ {
json::const_iterator it_begin = j.cbegin(); json::const_iterator it_begin = j_const.cbegin();
json::const_iterator it_end = j.cend(); json::const_iterator it_end = j_const.cend();
auto it = it_begin; auto it = it_begin;
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j_const["A"]);
it++; it++;
CHECK(it != it_begin); CHECK(it != it_begin);
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j_const["B"]);
++it; ++it;
CHECK(it != it_begin); CHECK(it != it_begin);
CHECK(it != it_end); CHECK(it != it_end);
CHECK(*it == j_const["C"]);
++it;
CHECK(it != it_begin);
CHECK(it == it_end);
}
SECTION("json + rbegin/rend")
{
json::reverse_iterator it_begin = j.rbegin();
json::reverse_iterator it_end = j.rend();
auto it = it_begin;
CHECK(it != it_end);
CHECK(*it == j["C"]);
it++;
CHECK(it != it_begin);
CHECK(it != it_end);
CHECK(*it == j["B"]);
++it;
CHECK(it != it_begin);
CHECK(it != it_end);
CHECK(*it == j["A"]);
++it;
CHECK(it != it_begin);
CHECK(it == it_end);
}
SECTION("json + crbegin/crend")
{
json::const_reverse_iterator it_begin = j.crbegin();
json::const_reverse_iterator it_end = j.crend();
auto it = it_begin;
CHECK(it != it_end);
CHECK(*it == j["C"]);
it++;
CHECK(it != it_begin);
CHECK(it != it_end);
CHECK(*it == j["B"]);
++it;
CHECK(it != it_begin);
CHECK(it != it_end);
CHECK(*it == j["A"]);
++it;
CHECK(it != it_begin);
CHECK(it == it_end);
}
SECTION("const json + crbegin/crend")
{
json::const_reverse_iterator it_begin = j_const.crbegin();
json::const_reverse_iterator it_end = j_const.crend();
auto it = it_begin;
CHECK(it != it_end);
CHECK(*it == j["C"]);
it++;
CHECK(it != it_begin);
CHECK(it != it_end);
CHECK(*it == j["B"]);
++it;
CHECK(it != it_begin);
CHECK(it != it_end);
CHECK(*it == j["A"]);
++it; ++it;
CHECK(it != it_begin); CHECK(it != it_begin);
@ -2812,6 +3130,81 @@ TEST_CASE("iterators")
CHECK(it != j_const.cend()); CHECK(it != j_const.cend());
CHECK(*it == j_const); CHECK(*it == j_const);
} }
SECTION("json + rbegin/rend")
{
json::reverse_iterator it = j.rbegin();
CHECK(it != j.rend());
CHECK(*it == j);
it++;
CHECK(it != j.rbegin());
CHECK(it == j.rend());
it--;
CHECK(it == j.rbegin());
CHECK(it != j.rend());
CHECK(*it == j);
++it;
CHECK(it != j.rbegin());
CHECK(it == j.rend());
--it;
CHECK(it == j.rbegin());
CHECK(it != j.rend());
CHECK(*it == j);
}
SECTION("json + crbegin/crend")
{
json::const_reverse_iterator it = j.crbegin();
CHECK(it != j.crend());
CHECK(*it == j);
it++;
CHECK(it != j.crbegin());
CHECK(it == j.crend());
it--;
CHECK(it == j.crbegin());
CHECK(it != j.crend());
CHECK(*it == j);
++it;
CHECK(it != j.crbegin());
CHECK(it == j.crend());
--it;
CHECK(it == j.crbegin());
CHECK(it != j.crend());
CHECK(*it == j);
}
SECTION("const json + crbegin/crend")
{
json::const_reverse_iterator it = j_const.crbegin();
CHECK(it != j_const.crend());
CHECK(*it == j_const);
it++;
CHECK(it != j_const.crbegin());
CHECK(it == j_const.crend());
it--;
CHECK(it == j_const.crbegin());
CHECK(it != j_const.crend());
CHECK(*it == j_const);
++it;
CHECK(it != j_const.crbegin());
CHECK(it == j_const.crend());
--it;
CHECK(it == j_const.crbegin());
CHECK(it != j_const.crend());
CHECK(*it == j_const);
}
} }
SECTION("number (float)") SECTION("number (float)")
@ -2918,6 +3311,81 @@ TEST_CASE("iterators")
CHECK(it != j_const.cend()); CHECK(it != j_const.cend());
CHECK(*it == j_const); CHECK(*it == j_const);
} }
SECTION("json + rbegin/rend")
{
json::reverse_iterator it = j.rbegin();
CHECK(it != j.rend());
CHECK(*it == j);
it++;
CHECK(it != j.rbegin());
CHECK(it == j.rend());
it--;
CHECK(it == j.rbegin());
CHECK(it != j.rend());
CHECK(*it == j);
++it;
CHECK(it != j.rbegin());
CHECK(it == j.rend());
--it;
CHECK(it == j.rbegin());
CHECK(it != j.rend());
CHECK(*it == j);
}
SECTION("json + crbegin/crend")
{
json::const_reverse_iterator it = j.crbegin();
CHECK(it != j.crend());
CHECK(*it == j);
it++;
CHECK(it != j.crbegin());
CHECK(it == j.crend());
it--;
CHECK(it == j.crbegin());
CHECK(it != j.crend());
CHECK(*it == j);
++it;
CHECK(it != j.crbegin());
CHECK(it == j.crend());
--it;
CHECK(it == j.crbegin());
CHECK(it != j.crend());
CHECK(*it == j);
}
SECTION("const json + crbegin/crend")
{
json::const_reverse_iterator it = j_const.crbegin();
CHECK(it != j_const.crend());
CHECK(*it == j_const);
it++;
CHECK(it != j_const.crbegin());
CHECK(it == j_const.crend());
it--;
CHECK(it == j_const.crbegin());
CHECK(it != j_const.crend());
CHECK(*it == j_const);
++it;
CHECK(it != j_const.crbegin());
CHECK(it == j_const.crend());
--it;
CHECK(it == j_const.crbegin());
CHECK(it != j_const.crend());
CHECK(*it == j_const);
}
} }
SECTION("null") SECTION("null")
@ -2951,6 +3419,24 @@ TEST_CASE("iterators")
json::const_iterator it_end = j_const.cend(); json::const_iterator it_end = j_const.cend();
CHECK(it_begin == it_end); CHECK(it_begin == it_end);
} }
SECTION("json + rbegin/rend")
{
json::reverse_iterator it = j.rbegin();
CHECK(it == j.rend());
}
SECTION("json + crbegin/crend")
{
json::const_reverse_iterator it = j.crbegin();
CHECK(it == j.crend());
}
SECTION("const json + crbegin/crend")
{
json::const_reverse_iterator it = j_const.crbegin();
CHECK(it == j_const.crend());
}
} }
} }