Skip to content

Commit

Permalink
Add support for C++11 range-based for-loop
Browse files Browse the repository at this point in the history
for(auto &o : my_json_value->u.object)
{
std::cout << o.name << std::endl;
}
And similar for arrays. No type checking, unfortunately - I couldn't
manage that.

Fix indentation
  • Loading branch information
LB-- committed Mar 27, 2013
1 parent 8ea0f50 commit b445038
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions json.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,31 @@ typedef struct _json_value

} * values;

#if defined(__cplusplus) && __cplusplus >= 201103L
decltype(values) begin () const
{ return values;
}
decltype(values) end () const
{ return values + length;
}
#endif

} object;

struct
{
unsigned int length;
struct _json_value ** values;

#if defined(__cplusplus) && __cplusplus >= 201103L
decltype(values) begin () const
{ return values;
}
decltype(values) end () const
{ return values + length;
}
#endif

} array;

} u;
Expand Down

0 comments on commit b445038

Please sign in to comment.