Finish C++14 library additions.

This commit is contained in:
Anthony Calandra
2016-11-04 19:42:27 -07:00
parent 624dcf4e8a
commit 2308d8e199

View File

@@ -34,6 +34,7 @@ C++14 includes the following new language features:
C++14 includes the following new library features: C++14 includes the following new library features:
- [user-defined literals for standard library types](#user-defined-literals-for-standard-library-types) - [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 ## C++17 Language Features
@@ -436,6 +437,24 @@ day.count(); // == 24
std::chrono::duration_cast<std::chrono::minutes>(day).count(); // == 1440 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 ## C++11 Language Features
TODO TODO