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

Detailed Description

Outline

Purpose

Provide functionality of the corresponding C++ Standard header.

Canonical header: bsl_chrono.h

Description

This component is for internal use only. Please include <bsl_chrono.h> directly. This component imports symbols declared in the <chrono> header file implemented in the standard library provided by the compiler vendor.

User-defined literals

This component provides a set of user-defined literals (UDL) to form bsl::chrono::duration objects with various duration periods such as hours, minutes, seconds, milliseconds, microseconds and nanoseconds. The ud-suffixes are preceded with the _ symbol to distinguish between the bsl-chrono's UDLs and the std-chrono's UDLs introduced in the C++14 standard and implemented in the standard library. Note that bsl-chrono's UDLs, unlike the std-chrono's UDLs, can be used in a client's code if the current compiler supports the C++11 standard.

Also note that bsl-chrono's UDL operators are declared in the bsl::literals::chrono_literals namespace, where literals and chrono_literals are inline namespaces. Access to these operators can be gained with either using namespace bsl::literals, using namespace bsl::chrono_literals or using namespace bsl::literals::chrono_literals. But we recommend using namespace bsl::chrono_literals to minimize the scope of the using declaration.

C++20 CalendarTZ feature on Windows

This feature has been provided by MSVC++ compiler since VS 2019 16.10. But that release was shipped with the following important note:

"While the STL generally provides all features on all supported versions of Windows, leap seconds and time zones (which change over time) require OS support that was added to Windows 10. Specifically, updating the leap second database requires Windows 10 version 1809 or later, and time zones require <tt>icu.dll</tt> which is provided by Windows 10 version 1903/19H1 or later. This applies to both client and server OSes; note that Windows Server 2019 is based on Windows 10 version 1809."

If the feature is used on a host that doesn't provide icu.dll, an exception with "The specified module could not be found." message will be thrown. That is why this feature is disabled by default on Windows.

Usage

In this section we show intended use of this component.

Example 1: Basic bsl-chrono's UDLs Usage

This example demonstrates basic use of user-defined literal operators.

First, we provide an access to bsl-chrono's UDLs.

using namespace bsl::chrono_literals;

Then, we construct two duration objects that represent a 24-hours and a half an hour time intervals using operator "" _h.

auto hours_in_a_day = 24_h;
auto halfhour = 0.5_h;

Finally, stream the two objects to stdout:

printf("one day is %lld hours\n",
static_cast<long long>(hours_in_a_day.count()));
printf("half an hour is %.1f hours\n",
static_cast<double>(halfhour.count()));

The streaming operator produces output in the following format on stdout:

one day is 24 hours
half an hour is 0.5 hours