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
bee6d698
Commit
bee6d698
authored
Jul 07, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some useful functions to PyList
parent
0a3c951f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
7 deletions
+16
-7
rt/include/python/builtins/list.hpp
rt/include/python/builtins/list.hpp
+16
-7
No files found.
rt/include/python/builtins/list.hpp
View file @
bee6d698
...
@@ -5,20 +5,31 @@
...
@@ -5,20 +5,31 @@
#ifndef TYPON_LIST_HPP
#ifndef TYPON_LIST_HPP
#define TYPON_LIST_HPP
#define TYPON_LIST_HPP
#include <algorithm>
#include <ostream>
#include <ostream>
#include <vector>
#include <vector>
// TODO: Hyrum's Law, maybe consider using composition instead to not expose
// that this is a std::vector?
template
<
typename
T
>
class
PyList
{
template
<
typename
T
>
class
PyList
{
public:
public:
PyList
(
std
::
shared_ptr
<
std
::
vector
<
T
>>
&&
v
)
:
_v
(
std
::
move
(
v
))
{}
PyList
(
std
::
shared_ptr
<
std
::
vector
<
T
>>
&&
v
)
:
_v
(
std
::
move
(
v
))
{}
PyList
(
std
::
vector
<
T
>
&&
v
)
:
_v
(
std
::
move
(
std
::
make_shared
<
std
::
vector
<
T
>>
(
std
::
move
(
v
))))
{}
PyList
(
std
::
vector
<
T
>
&&
v
)
:
_v
(
std
::
move
(
std
::
make_shared
<
std
::
vector
<
T
>>
(
std
::
move
(
v
))))
{}
PyList
(
std
::
initializer_list
<
T
>
&&
v
)
:
_v
(
std
::
make_shared
<
std
::
vector
<
T
>>
(
std
::
move
(
v
)))
{}
PyList
(
std
::
initializer_list
<
T
>
&&
v
)
:
_v
(
std
::
make_shared
<
std
::
vector
<
T
>>
(
std
::
move
(
v
)))
{}
PyList
()
:
_v
(
std
::
make_shared
<
std
::
vector
<
T
>>
())
{}
PyList
()
:
_v
(
std
::
make_shared
<
std
::
vector
<
T
>>
())
{}
auto
begin
()
const
{
return
_v
->
begin
();
}
auto
end
()
const
{
return
_v
->
end
();
}
auto
append
(
const
T
&
x
)
{
_v
->
push_back
(
x
);
}
auto
py_contains
(
const
T
&
x
)
const
{
return
std
::
find
(
_v
->
begin
(),
_v
->
end
(),
x
)
!=
_v
->
end
();
}
/*operator std::vector<T>() const {
/*operator std::vector<T>() const {
return std::vector<T>(this->begin(), this->end());
return std::vector<T>(this->begin(), this->end());
}
}
...
@@ -44,9 +55,7 @@ public:
...
@@ -44,9 +55,7 @@ public:
s
<<
']'
;
s
<<
']'
;
}
}
void
py_print
(
std
::
ostream
&
s
)
const
{
void
py_print
(
std
::
ostream
&
s
)
const
{
py_repr
(
s
);
}
py_repr
(
s
);
}
PyList
<
T
>
operator
+
(
const
PyList
<
T
>
&
other
)
const
{
PyList
<
T
>
operator
+
(
const
PyList
<
T
>
&
other
)
const
{
std
::
vector
<
T
>
v
;
std
::
vector
<
T
>
v
;
...
...
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