mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-17 01:54:36 +03:00
GCD and LCM.
This commit is contained in:
10
CPP17.md
10
CPP17.md
@@ -35,6 +35,7 @@ C++17 includes the following new library features:
|
||||
- [std::clamp](#stdclamp)
|
||||
- [std::reduce](#stdreduce)
|
||||
- [prefix sum algorithms](#prefix-sum-algorithms)
|
||||
- [gcd and lcm](#gcd-and-lcm)
|
||||
|
||||
## C++17 Language Features
|
||||
|
||||
@@ -590,6 +591,15 @@ std::transform_exclusive_scan(std::cbegin(a), std::cend(a),
|
||||
std::ostream_iterator<int>{ std::cout, " " }, 0, std::plus<>{}, times_ten); // 0 10 30
|
||||
```
|
||||
|
||||
### GCD and LCM
|
||||
Greatest common divisor (GCD) and least common multiple (LCM).
|
||||
```c++
|
||||
const int p = 9;
|
||||
const int q = 3;
|
||||
std::gcd(p, q); // == 3
|
||||
std::lcm(p, q); // == 9
|
||||
```
|
||||
|
||||
## Acknowledgements
|
||||
* [cppreference](http://en.cppreference.com/w/cpp) - especially useful for finding examples and documentation of new library features.
|
||||
* [C++ Rvalue References Explained](http://thbecker.net/articles/rvalue_references/section_01.html) - a great introduction I used to understand rvalue references, perfect forwarding, and move semantics.
|
||||
|
||||
10
README.md
10
README.md
@@ -65,6 +65,7 @@ C++17 includes the following new library features:
|
||||
- [std::clamp](#stdclamp)
|
||||
- [std::reduce](#stdreduce)
|
||||
- [prefix sum algorithms](#prefix-sum-algorithms)
|
||||
- [gcd and lcm](#gcd-and-lcm)
|
||||
|
||||
C++14 includes the following new language features:
|
||||
- [binary literals](#binary-literals)
|
||||
@@ -1254,6 +1255,15 @@ std::transform_exclusive_scan(std::cbegin(a), std::cend(a),
|
||||
std::ostream_iterator<int>{ std::cout, " " }, 0, std::plus<>{}, times_ten); // 0 10 30
|
||||
```
|
||||
|
||||
### GCD and LCM
|
||||
Greatest common divisor (GCD) and least common multiple (LCM).
|
||||
```c++
|
||||
const int p = 9;
|
||||
const int q = 3;
|
||||
std::gcd(p, q); // == 3
|
||||
std::lcm(p, q); // == 9
|
||||
```
|
||||
|
||||
## C++14 Language Features
|
||||
|
||||
### Binary literals
|
||||
|
||||
Reference in New Issue
Block a user