mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-17 18:14:36 +03:00
Finish C++14 library additions.
This commit is contained in:
19
README.md
19
README.md
@@ -34,6 +34,7 @@ C++14 includes the following new language features:
|
||||
|
||||
C++14 includes the following new library features:
|
||||
- [user-defined literals for standard library types](#user-defined-literals-for-standard-library-types)
|
||||
- [compile-time integer sequences](#compile---time-integer-sequences)
|
||||
|
||||
## C++17 Language Features
|
||||
|
||||
@@ -436,6 +437,24 @@ day.count(); // == 24
|
||||
std::chrono::duration_cast<std::chrono::minutes>(day).count(); // == 1440
|
||||
```
|
||||
|
||||
### Compile-time integer sequences
|
||||
The class template `std::integer_sequence` represents a compile-time sequence of integers. There are a few helpers built on top:
|
||||
* `std::make_integer_sequence<T, N...>` - creates a sequence of `0, ..., N - 1` with type `T`.
|
||||
* `std::index_sequence_for<T...>` - converts a template parameter pack into an integer sequence.
|
||||
|
||||
Convert an array into a tuple:
|
||||
```c++
|
||||
template<typename Array, std::size_t... I>
|
||||
decltype(auto) a2t_impl(const Array& a, std::integer_sequence<std::size_t, I...>) {
|
||||
return std::make_tuple(a[I]...);
|
||||
}
|
||||
|
||||
template<typename T, std::size_t N, typename Indices = std::make_index_sequence<N>>
|
||||
decltype(auto) a2t(const std::array<T, N>& a) {
|
||||
return a2t_impl(a, Indices());
|
||||
}
|
||||
```
|
||||
|
||||
## C++11 Language Features
|
||||
TODO
|
||||
|
||||
|
||||
Reference in New Issue
Block a user