Skip to content

Commit 623568a

Browse files
committed
Correct a conversion error
1 parent 4c24bbd commit 623568a

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

code_snippets/chapter05/chapter05_13-002_array_to_tuple.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@
1414
#include <utility>
1515

1616
template<typename array_type,
17-
unsigned... I>
17+
std::size_t... I>
1818
constexpr auto array_to_tuple_helper(
1919
const array_type& a,
2020
std::index_sequence<I...>)
2121
-> decltype(auto)
2222
{
23-
return std::make_tuple(1.0F * a[I]...);
23+
return
24+
std::make_tuple(1.0F * static_cast<float>(a[I])...);
2425
}
2526

2627
template<typename T,
27-
const unsigned N,
28+
const std::size_t N,
2829
typename indices =
2930
std::make_index_sequence<N>>
3031
constexpr auto
@@ -34,16 +35,15 @@ constexpr auto
3435
return array_to_tuple_helper(a, indices());
3536
}
3637

37-
std::array<int, 4> a =
38+
std::array<int, std::size_t { UINT8_C(4) }> a =
3839
{{
3940
1, 2, 3, 4
4041
}};
4142

4243
// Convert int array to float tuple.
4344
// Here, the type of tpl is
4445
// std::tuple<float, float, float, float>.
45-
std::tuple<float, float, float, float> tpl
46-
{ array_to_tuple(a) };
46+
auto tpl { array_to_tuple(a) };
4747

4848
auto main() -> int;
4949

0 commit comments

Comments
 (0)