Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
libsimple_support
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
namark
libsimple_support
Commits
703a75b6
Commit
703a75b6
authored
3 years ago
by
namark
Browse files
Options
Downloads
Patches
Plain Diff
indirect_range_referring_reference_t
basically ranges::ref_view
parent
dd6ea902
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
source/simple/support/misc.hpp
+45
-10
45 additions, 10 deletions
source/simple/support/misc.hpp
unit_tests/misc.cpp
+4
-1
4 additions, 1 deletion
unit_tests/misc.cpp
with
49 additions
and
11 deletions
source/simple/support/misc.hpp
+
45
−
10
View file @
703a75b6
...
...
@@ -136,31 +136,66 @@ namespace simple::support
return
{
begin
,
static_cast
<
std
::
string_view
::
size_type
>
(
end
-
begin
)};
}
// NOTE: maybe put in algorithm range wrappers instead?
// NOTE: maybe put in algorithm/range_wrappers.hpp instead?
// problem is, range_wrappers.hpp doesn't depend on anything,
// so need to also parameterize the range type, to keep it that way.
// A bit unrealisitic to expect ::limit() or arithmetic for generic range.
// but really don't want the includeee
template
<
typename
Container
,
typename
=
std
::
enable_if_t
<
is_range_v
<
Container
>
>>
class
ind
ex
_range
class
ind
irect
_range
_referring_reference_t
{
public:
using
container_type
=
Container
;
using
size_type
=
typename
container_type
::
size_type
;
using
iterator
=
typename
container_type
::
iterator
;
using
const_iterator
=
typename
container_type
::
const_iterator
;
explicit
indirect_range_referring_reference_t
(
Container
&
container
)
:
container
(
&
container
)
{}
auto
begin
()
const
{
using
std
::
begin
;
return
begin
(
*
container
);
}
auto
end
()
const
{
using
std
::
end
;
return
end
(
*
container
);
}
private
:
Container
*
container
;
};
template
<
typename
Container
,
typename
=
std
::
enable_if_t
<
is_range_v
<
Container
>
>>
class
index_range
{
public:
using
container_type
=
Container
;
using
size_type
=
typename
container_type
::
size_type
;
explicit
index_range
(
Container
&
container
,
Container
container
,
range
<
size_type
>
index
=
range
<
size_type
>::
limit
()
)
:
container
(
&
container
),
container
(
std
::
move
(
container
)
)
,
index
(
index
)
{}
explicit
index_range
(
Container
&
container
,
Container
container
,
range
<
typename
Container
::
const_iterator
>
iterator_range
)
:
container
(
&
container
),
index
(
iterator_range
-
container
.
begin
())
container
(
std
::
move
(
container
)),
// TODO: ADL the begin
index
(
iterator_range
-
this
->
container
.
begin
())
{}
auto
begin
()
const
...
...
@@ -169,7 +204,7 @@ namespace simple::support
{
return
iter_at
(
index
.
upper
());
}
private
:
Container
*
container
;
Container
container
;
range
<
size_type
>
index
;
auto
iter_at
(
size_type
index
)
const
...
...
@@ -178,8 +213,8 @@ namespace simple::support
using
std
::
end
;
using
std
::
clamp
;
auto
begin_
=
begin
(
*
container
);
auto
end_
=
end
(
*
container
);
auto
begin_
=
begin
(
container
);
auto
end_
=
end
(
container
);
// TODO: use container.size() if available
return
begin_
+
clamp
(
index
,
size_type
{},
...
...
This diff is collapsed.
Click to expand it.
unit_tests/misc.cpp
+
4
−
1
View file @
703a75b6
...
...
@@ -115,7 +115,10 @@ void RangeReference()
assert
(
std
::
equal
(
begin
(
temporef
),
end
(
temporef
),
begin
(
prefix
),
end
(
prefix
))
);
index_range
permaref
(
stuff
,
{
begin
(
stuff
),
end
(
stuff
)});
index_range
permaref
{
indirect_range_referring_reference_t
(
stuff
),
{
begin
(
stuff
),
end
(
stuff
)}
};
assert
(
std
::
equal
(
begin
(
permaref
),
end
(
permaref
),
begin
(
prefix
),
end
(
prefix
))
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment