FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
co-cpp19/src/array19.lib/array19/WithIndex.h at develop · basicpp/co-cpp19 · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
basicpp
/
co-cpp19
Public
Notifications
You must be signed in to change notification settings
Fork
3
Star
14
Code
Issues
1
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
co-cpp19
/
src
/
array19.lib
/
array19
/
WithIndex.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
42 lines (31 loc) · 1.15 KB
Breadcrumbs
co-cpp19
/
src
/
array19.lib
/
array19
/
WithIndex.h
Copy path
File metadata and controls
42 lines (31 loc) · 1.15 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
#
pragma
once
#
include
"
adlRange.h
"
#
include
<
stddef.h
>
//
size_t
namespace
array19
{
//
/ Iterate a container with indices
//
/ usage:
//
/ for(auto [value, index] : WithIndex{container});
template
<
class
C
>
struct
WithIndex
{
using
It =
decltype
(adlBegin(*
static_cast
<C*>(
nullptr
)));
using
Res =
decltype
(**
static_cast
<It*>(
nullptr
));
//
not using std::pair to avoid reference hassles
struct
result
{
Res value;
size_t
index;
};
//
minimal iterator that is just enough to run ranged for loop
struct
iterator
{
It it;
size_t
index{};
[[nodiscard]]
constexpr
auto
operator
*()
const
-> result {
return
{*it, index}; }
[[nodiscard]]
constexpr
bool
operator
!=(
const
It& o)
const
{
return
it != o; }
constexpr
auto
operator
++() -> iterator& {
return
(++it, ++index, *
this
); }
};
constexpr
WithIndex
(C& c)
noexcept
: c(&c) {}
[[nodiscard]]
constexpr
auto
begin
() -> iterator {
return
iterator{
adlBegin
(*c), {}}; }
[[nodiscard]]
constexpr
auto
end
() -> It {
return
adlEnd
(*c); }
private:
C* c;
};
template
<
class
C
>
WithIndex
(C&) -> WithIndex<C>;
}
//
namespace array19
Back
|
FazBrowse Home
|
New Git URL