BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslstl_iomanip

Detailed Description

Outline

Purpose

Provide BSL implementations for standard <iomanip> features.

Classes

Canonical header: bsl_iomanip.h

See also
bsl+bslhdrs

Description

This component is for internal use only. Please include <bsl_iomanip.h> instead.

This component exists to provide BSL implementations for facilities in the standard <iomanip> header. While most of the facilities in bsl_iomanip.h are simply aliases to the platform standard library, some of them need BSL specific implementations. For example, this component provides implementations for bsl::quoted overloads that accept bsl::basic_string and proprietary bsl::string_view objects.

Usage

This section illustrates intended use of this component.

Example 1: Basic Use of bsl::quoted

Suppose we want to serialize some data into JSON.

First, we define a struct, Employee, to contain the data:

struct Employee {
bsl::string d_firstName;
bsl::string d_lastName;
int d_age;
};
Definition bslstl_string.h:1281

Then, we create an Employee object and populate it with data:

Employee john;
john.d_firstName = "John";
john.d_lastName = "Doe";
john.d_age = 20;

Now, we create an output stream and manually construct the JSON string using bsl::quoted:

ss << '{' << '\n';
ss << bsl::quoted("firstName");
ss << ':';
ss << bsl::quoted(john.d_firstName);
ss << ',' << '\n';
ss << bsl::quoted("lastName");
ss << ':';
ss << bsl::quoted(john.d_lastName);
ss << ',' << '\n';
ss << bsl::quoted("age");
ss << ':';
ss << john.d_age;
ss << '\n' << '}';
Definition bslstl_stringstream.h:184

Finally, we check out the JSON string:

bsl::string expected = "{\n"
"\"firstName\":\"John\",\n"
"\"lastName\":\"Doe\",\n"
"\"age\":20\n"
"}";
assert(expected == ss.str());
void str(const StringType &value)
Definition bslstl_stringstream.h:545

The output should look like:

{
"firstName":"John",
"lastName":"Doe",
"age":20
}