Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon-compiler
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
typon
typon-compiler
Commits
7281d632
Commit
7281d632
authored
Aug 18, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finish implementation of range
parent
9ced6e74
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
2 deletions
+21
-2
rt/include/python/builtins/range.hpp
rt/include/python/builtins/range.hpp
+21
-2
No files found.
rt/include/python/builtins/range.hpp
View file @
7281d632
...
...
@@ -7,16 +7,35 @@
#include <ranges>
namespace
view
=
std
::
views
;
#include <python/basedef.hpp>
auto
stride
=
[](
int
n
)
{
return
[
s
=
-
1
,
n
](
auto
const
&
)
mutable
{
s
=
(
s
+
1
)
%
n
;
return
!
s
;
};
};
// todo: proper range support
struct
range_s
:
TyBuiltin
<
range_s
>
{
template
<
typename
T
>
auto
sync
(
T
stop
)
{
return
s
td
::
views
::
iota
(
0
,
stop
);
}
auto
sync
(
T
stop
)
{
return
s
ync
(
0
,
stop
);
}
template
<
typename
T
>
auto
sync
(
T
start
,
T
stop
)
{
return
std
::
views
::
iota
(
start
,
stop
);
}
auto
sync
(
T
start
,
T
stop
,
T
step
=
1
)
{
// https://www.modernescpp.com/index.php/c-20-pythons-map-function/
if
(
step
==
0
)
{
throw
std
::
invalid_argument
(
"Step cannot be 0"
);
}
auto
Step
=
start
<
stop
?
step
:
-
step
;
auto
Begin
=
std
::
min
(
start
,
stop
);
auto
End
=
Step
<
0
?
Begin
:
std
::
max
(
start
,
stop
);
return
view
::
iota
(
Begin
,
End
)
|
view
::
filter
(
stride
(
std
::
abs
(
Step
)))
|
view
::
transform
([
start
,
stop
](
std
::
size_t
i
){
return
start
<
stop
?
i
:
stop
-
(
i
-
start
);
});
}
}
range
;
#endif // TYPON_RANGE_HPP
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment