FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Cpp20Features/to_array.cpp at master · icEngineer-tech/Cpp20Features · GitHub
icEngineer-tech
/
Cpp20Features
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Cpp20Features
/
to_array.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
30 lines (26 loc) · 806 Bytes
Breadcrumbs
Cpp20Features
/
to_array.cpp
Copy path
File metadata and controls
30 lines (26 loc) · 806 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//
convert a C_Style array into the new Cpp_Style array (the container of STL)
#
include
<
iostream
>
#
include
<
array
>
//
---------------------------------------------------------- (2)
template
<
typename
T, std::
size_t
N, std::
size_t
...S>
consteval
std::array<T, N>
to_array_impl
(T (&a)[N], std::index_sequence<S...>)
{
return
{ { a[S]... } };
}
template
<
typename
T, std::
size_t
N>
consteval
std::array<T, N>
to_array
(T (&a)[N])
{
return
to_array_impl
(a, std::make_index_sequence<N>());
}
//
-----------------------------------------------------------
int
main
()
{
//
this what the standard gives us (1)
int
tab[
5
]{
14
,
8
,
2
,
0
,
4
};
std::array<
int
,
5
> io =
std::to_array
(tab);
for
(
auto
i : io)
std::cout << i <<
"
"
;
//
look at this beauty of C++ aha
//
same code can go here for (2)
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL