From 2308d8e1990fb0e6cd9760052bcdfa710f7ab783 Mon Sep 17 00:00:00 2001 From: Anthony Calandra Date: Fri, 4 Nov 2016 19:42:27 -0700 Subject: [PATCH] Finish C++14 library additions. --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 48df5de..a195932 100644 --- a/README.md +++ b/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(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` - creates a sequence of `0, ..., N - 1` with type `T`. +* `std::index_sequence_for` - converts a template parameter pack into an integer sequence. + +Convert an array into a tuple: +```c++ +template +decltype(auto) a2t_impl(const Array& a, std::integer_sequence) { + return std::make_tuple(a[I]...); +} + +template> +decltype(auto) a2t(const std::array& a) { + return a2t_impl(a, Indices()); +} +``` + ## C++11 Language Features TODO