From 7d91a174a2881b481a81c075b97b76bf3ee7603c Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 19 May 2017 01:43:30 +0300 Subject: [PATCH] Fix tuple_cat example a bit --- doc/html/mp11.html | 12 ++++++------ doc/mp11/examples.qbk | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/doc/html/mp11.html b/doc/html/mp11.html index 72adda5..103067c 100644 --- a/doc/html/mp11.html +++ b/doc/html/mp11.html @@ -474,7 +474,7 @@
std::array<int, 2> t1{ 1, 2 };
 std::array<float, 3> t2{ 3.0f, 4.0f, 5.0f };
 
-auto result = ::tuple_cat( t1, std::move( t2 ) );
+auto result = ::tuple_cat( t1, t2 );
 

Let's fix these one by one. Support for move-only types is easy, if one knows @@ -542,11 +542,11 @@

What we need is, given a tuple-like type Tp, to obtain mp_list<std::tuple_element<0, - Tp>, - std::tuple_element<1, Tp>, ..., std::tuple_element<N-1, Tp>>, where N + Tp>::type, std::tuple_element<1, + Tp>::type, ..., std::tuple_element<N-1, Tp>::type>, where N is tuple_size<Tp>::value. Here's one way to do it:

-
template<class T, class I> using tuple_element = std::tuple_element_t<I::value, T>;
+
template<class T, class I> using tuple_element = typename std::tuple_element<I::value, T>::type;
 template<class T> using from_tuple_like = mp_product<tuple_element, mp_list<T>, mp_iota<std::tuple_size<T>>>;
 

@@ -591,7 +591,7 @@ template<class T> using remove_cv_ref = typename std::remove_cv< typename std::remove_reference<T>::type>::type; -template<class T, class I> using tuple_element = std::tuple_element_t<I::value, T>; +template<class T, class I> using tuple_element = typename std::tuple_element<I::value, T>::type; template<class T> using from_tuple_like = mp_product<tuple_element, mp_list<T>, mp_iota<std::tuple_size<T>>>; template<class... Tp, @@ -2317,7 +2317,7 @@ - +

Last revised: May 18, 2017 at 11:57:59 GMT

Last revised: May 18, 2017 at 22:41:31 GMT


diff --git a/doc/mp11/examples.qbk b/doc/mp11/examples.qbk index 9d85678..9394bd3 100644 --- a/doc/mp11/examples.qbk +++ b/doc/mp11/examples.qbk @@ -148,7 +148,7 @@ that support `tuple_size`, `tuple_element`, and `get`), while our implementation std::array t1{ 1, 2 }; std::array t2{ 3.0f, 4.0f, 5.0f }; - auto result = ::tuple_cat( t1, std::move( t2 ) ); + auto result = ::tuple_cat( t1, t2 ); Let's fix these one by one. Support for move-only types is easy, if one knows where to look. The problem is that `Tp` that we're passing to the helper `tuple_cat_` is (correctly) `tuple&&, unique_ptr&&>`, @@ -193,10 +193,10 @@ the corresponding `mp_list`. Technically, a more principled approach would've been to return `std::tuple`, but here `mp_list` will prove more convenient. -What we need is, given a tuple-like type `Tp`, to obtain `mp_list, std::tuple_element<1, Tp>, -..., std::tuple_element>`, where `N` is `tuple_size::value`. Here's one way to do it: +What we need is, given a tuple-like type `Tp`, to obtain `mp_list::type, std::tuple_element<1, Tp>::type, +..., std::tuple_element::type>`, where `N` is `tuple_size::value`. Here's one way to do it: - template using tuple_element = std::tuple_element_t; + template using tuple_element = typename std::tuple_element::type; template using from_tuple_like = mp_product, mp_iota>>; (`mp_iota` is an algorithm that returns an `mp_list` with elements `mp_size_t<0>`, `mp_size_t<1>`, ..., `mp_size_t`.) @@ -224,7 +224,7 @@ With all these fixes applied, our fully operational `tuple_cat` now looks like t template using remove_cv_ref = typename std::remove_cv< typename std::remove_reference::type>::type; - template using tuple_element = std::tuple_element_t; + template using tuple_element = typename std::tuple_element::type; template using from_tuple_like = mp_product, mp_iota>>; template