Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tom Niget
typon
Commits
a9e353b0
Commit
a9e353b0
authored
Jul 07, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make PyDict a refcounted type
parent
cfe47b7b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
2 deletions
+45
-2
rt/include/python/builtins/dict.hpp
rt/include/python/builtins/dict.hpp
+45
-2
No files found.
rt/include/python/builtins/dict.hpp
View file @
a9e353b0
...
...
@@ -6,7 +6,7 @@
#define TYPON_DICT_HPP
#include <unordered_map>
/*
template <typename K, typename V>
class PyDict : public std::unordered_map<K, V> {
public:
...
...
@@ -81,6 +81,49 @@ public:
};
template <typename K, typename V>
PyDict
(
std
::
initializer_list
<
std
::
pair
<
K
,
V
>>
)
->
PyDict
<
K
,
V
>
;
PyDict(std::initializer_list<std::pair<K, V>>) -> PyDict<K, V>;*/
template
<
typename
K
,
typename
V
>
class
PyDict
{
public:
PyDict
(
std
::
shared_ptr
<
std
::
unordered_map
<
K
,
V
>>
&&
m
)
:
_m
(
std
::
move
(
m
))
{}
PyDict
(
std
::
unordered_map
<
K
,
V
>
&&
m
)
:
_m
(
std
::
move
(
std
::
make_shared
<
std
::
unordered_map
<
K
,
V
>>
(
std
::
move
(
m
))))
{}
PyDict
(
std
::
initializer_list
<
std
::
pair
<
K
,
V
>>
&&
m
)
:
_m
(
std
::
make_shared
<
std
::
unordered_map
<
K
,
V
>>
(
std
::
move
(
m
)))
{}
PyDict
()
:
_m
(
std
::
make_shared
<
std
::
unordered_map
<
K
,
V
>>
())
{}
auto
begin
()
const
{
return
_m
->
begin
();
}
auto
end
()
const
{
return
_m
->
end
();
}
auto
py_contains
(
const
K
&
k
)
const
{
return
_m
->
find
(
k
)
!=
_m
->
end
();
}
constexpr
const
V
&
operator
[](
const
K
&
k
)
const
{
return
(
*
_m
)[
k
];
}
constexpr
V
&
operator
[](
const
K
&
k
)
{
return
(
*
_m
)[
k
];
}
size_t
py_len
()
const
{
return
_m
->
size
();
}
void
py_repr
(
std
::
ostream
&
s
)
const
{
s
<<
'{'
;
if
(
_m
->
size
()
>
0
)
{
repr_to
(
_m
->
begin
()
->
first
,
s
);
s
<<
": "
;
repr_to
(
_m
->
begin
()
->
second
,
s
);
for
(
auto
it
=
++
_m
->
begin
();
it
!=
_m
->
end
();
it
++
)
{
s
<<
", "
;
repr_to
(
it
->
first
,
s
);
s
<<
": "
;
repr_to
(
it
->
second
,
s
);
}
}
s
<<
'}'
;
}
void
py_print
(
std
::
ostream
&
s
)
const
{
py_repr
(
s
);
}
private:
std
::
shared_ptr
<
std
::
unordered_map
<
K
,
V
>>
_m
;
};
#endif // TYPON_DICT_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