|
BDE 4.14.0 Production release
|
Provide user-defined literals for bdljsn::Json objects.
This component provides a namespace, bdljsn::JsonLiterals, in which operators for the user-defined literal suffix "_json" are defined. Users can define a using declaration for the JsonLiterals namespace, and apply the "_json" suffix to literal text containing JSON to create bdljsn::Json objects (on platforms that support user defined literals).
For example:
The operator "" _json returns a bdljsn::Json object that allocates memory using the currently installed global allocator. Using the global allocator prevents inadvertently locking the default allocator, as may happen before main when using a JSON literal to initialize an object at global file-scope static storage duration. Note that while file scoped static objects can be useful in testing, we discourage their use in production code.
This section illustrates the intended use of this component.
This component provides a namespace in which user-defined literal operators for bdljsn::Json are defined. In this example we use a _json literal to initialize a bdljsn::Json object.
First, we define a user declaration for the appropriate namespace:
Then we create a bdljsn::Json object:
Notice that the user-defined literal operator will unconditionally invoke the bsls::Assert handler if the literal text is not valid JSON.