mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-16 17:47:02 +03:00
Add rounding functions for chrono durations and timepoints.
This commit is contained in:
12
CPP17.md
12
CPP17.md
@@ -39,6 +39,7 @@ C++17 includes the following new library features:
|
||||
- [gcd and lcm](#gcd-and-lcm)
|
||||
- [std::not_fn](#stdnot_fn)
|
||||
- [string conversion to/from numbers](#string-conversion-tofrom-numbers)
|
||||
- [rounding functions for chrono durations and timepoints](#rounding-functions-for-chrono-durations-and-timepoints)
|
||||
|
||||
## C++17 Language Features
|
||||
|
||||
@@ -686,6 +687,17 @@ if (ec == std::errc{}) { std::cout << n << std::endl; } // 123
|
||||
else { /* handle failure */ }
|
||||
```
|
||||
|
||||
### Rounding functions for chrono durations and timepoints
|
||||
Provides abs, round, ceil, and floor helper functions for `std::chrono::duration` and `std::chrono::time_point`.
|
||||
```c++
|
||||
using seconds = std::chrono::seconds;
|
||||
std::chrono::milliseconds d{ 5500 };
|
||||
std::chrono::abs(d); // == 5s
|
||||
std::chrono::round<seconds>(d); // == 6s
|
||||
std::chrono::ceil<seconds>(d); // == 6s
|
||||
std::chrono::floor<seconds>(d); // == 5s
|
||||
```
|
||||
|
||||
## Acknowledgements
|
||||
* [cppreference](http://en.cppreference.com/w/cpp) - especially useful for finding examples and documentation of new library features.
|
||||
* [C++ Rvalue References Explained](http://web.archive.org/web/20240324121501/http://thbecker.net/articles/rvalue_references/section_01.html) - a great introduction I used to understand rvalue references, perfect forwarding, and move semantics.
|
||||
|
||||
12
README.md
12
README.md
@@ -70,6 +70,7 @@ C++17 includes the following new library features:
|
||||
- [gcd and lcm](#gcd-and-lcm)
|
||||
- [std::not_fn](#stdnot_fn)
|
||||
- [string conversion to/from numbers](#string-conversion-tofrom-numbers)
|
||||
- [rounding functions for chrono durations and timepoints](#rounding-functions-for-chrono-durations-and-timepoints)
|
||||
|
||||
C++14 includes the following new language features:
|
||||
- [binary literals](#binary-literals)
|
||||
@@ -1360,6 +1361,17 @@ if (ec == std::errc{}) { std::cout << n << std::endl; } // 123
|
||||
else { /* handle failure */ }
|
||||
```
|
||||
|
||||
### Rounding functions for chrono durations and timepoints
|
||||
Provides abs, round, ceil, and floor helper functions for `std::chrono::duration` and `std::chrono::time_point`.
|
||||
```c++
|
||||
using seconds = std::chrono::seconds;
|
||||
std::chrono::milliseconds d{ 5500 };
|
||||
std::chrono::abs(d); // == 5s
|
||||
std::chrono::round<seconds>(d); // == 6s
|
||||
std::chrono::ceil<seconds>(d); // == 6s
|
||||
std::chrono::floor<seconds>(d); // == 5s
|
||||
```
|
||||
|
||||
## C++14 Language Features
|
||||
|
||||
### Binary literals
|
||||
|
||||
Reference in New Issue
Block a user