Quick Links:

bal | bbl | bdl | bsl

Component bslstl_chrono
[Package bslstl]

Provide functionality of the corresponding C++ Standard header. More...

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.
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 %ld hours\n", 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