You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Functional style parsing for custom data members was requested in #267 and introduced in 0.157.0.
In 0.157.0, the _NAME_ convenience macros were augmented to allow an optional Mode parameter (JSONCONS_RDWR or JSONCONS_RDONLY) and three function objects, Match (value matches expected), From (convert from type known to jsoncons) and Into (convert into type known to jsoncons).
There are two issues.
First, providing a lambda expression for the Into function object will result in an error message such as "lambda-expression in unevaluated context" (at least until C++20), because the into function object is used inside a decltype specifier, and that breaks a restriction on lambda expressions. This restriction appears to have been removed in C++20. In the meantime, it needs to be noted that we cannot pass a lambda expression for this parameter. Instead we need to pass a free function, a struct object with the operator() defined, or a variable containing a lambda expression.
Second, when JSONCONS_RDONLY is provided for the Mode parameter, the From parameter is redundant, so it is more convenient to reverse the order of the From and Into parameters. This change has been made on master, and will be included in forthcoming version 0.158.0.
To illustrate, below is a version of the polymorphic shapes example that does not require a type member. More generally, the example shows how to augment the JSON output with name/value pairs that are not present in the class definition, and to perform type selection with them.
Functional style parsing for custom data members was requested in #267 and introduced in 0.157.0.
In 0.157.0, the
_NAME_
convenience macros were augmented to allow an optionalMode
parameter (JSONCONS_RDWR
orJSONCONS_RDONLY
) and three function objects,Match
(value matches expected),From
(convert from type known to jsoncons) andInto
(convert into type known to jsoncons).There are two issues.
First, providing a lambda expression for the
Into
function object will result in an error message such as "lambda-expression in unevaluated context" (at least until C++20), because theinto
function object is used inside adecltype
specifier, and that breaks a restriction on lambda expressions. This restriction appears to have been removed in C++20. In the meantime, it needs to be noted that we cannot pass a lambda expression for this parameter. Instead we need to pass a free function, a struct object with theoperator()
defined, or a variable containing a lambda expression.Second, when
JSONCONS_RDONLY
is provided for theMode
parameter, theFrom
parameter is redundant, so it is more convenient to reverse the order of theFrom
andInto
parameters. This change has been made on master, and will be included in forthcoming version 0.158.0.To illustrate, below is a version of the polymorphic shapes example that does not require a
type
member. More generally, the example shows how to augment the JSON output with name/value pairs that are not present in the class definition, and to perform type selection with them.Output:
The validation example (which provided a
From
but omitted theInto
function object) now becomesOutput:
The text was updated successfully, but these errors were encountered: