BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdlb_guidformatter

Detailed Description

Provide bsl::formatter specialization for bdlb::Guid.

Outline

Purpose

Provide bsl::formatter specialization for bdlb::Guid.

Classes

See also
bdlb_guid, bslfmt_format

Description

This component provides a partial specialization of the bsl::formatter class template for bdlb::Guid, enabling bdlb::Guid values to be used with bsl::format and its variants.

Format Specification

The supported format specification is a subset of the standard std::format grammar:

format-spec ::= [ [fill] align ] [ width ]
fill ::= any character other than '{' or '}'
align ::= '<' | '>' | '^'
width ::= non-negative-integer | '{' [ arg-id ] '}'

No sign, alternate-form (#), zero-pad (0), precision, or type specifiers are supported. The default alignment is left, matching the convention for string-like types. The formatted representation is always the canonical 36-character lowercase hexadecimal form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.

Usage

This section illustrates intended use of this component.

Example 1: Formatting a bdlb::Guid

Suppose we have a bdlb::Guid object and want to render it as a string:

const unsigned char raw[bdlb::Guid::k_GUID_NUM_BYTES] = {
0x5c, 0x9d, 0x4e, 0x53, 0x0d, 0xf1, 0x11, 0xe4,
0x91, 0x91, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 };
bdlb::Guid guid(raw);
bsl::string s = bsl::format("{}", guid);
assert(s == "5c9d4e53-0df1-11e4-9191-0800200c9a66");
Definition bdlb_guid.h:201
@ k_GUID_NUM_BYTES
Definition bdlb_guid.h:205
Definition bslstl_string.h:1252

Width, alignment, and fill are supported as they would be for a string:

bsl::string padded = bsl::format("{:*^40}", guid);
assert(padded == "**5c9d4e53-0df1-11e4-9191-0800200c9a66**");