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
776ac174
Commit
776ac174
authored
Mar 14, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Format
parent
c0f3f227
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
217 additions
and
271 deletions
+217
-271
.clang-format
.clang-format
+1
-3
rt/include/python/builtins.hpp
rt/include/python/builtins.hpp
+13
-21
rt/include/python/builtins/bool.hpp
rt/include/python/builtins/bool.hpp
+3
-4
rt/include/python/builtins/complex.hpp
rt/include/python/builtins/complex.hpp
+9
-14
rt/include/python/builtins/dict.hpp
rt/include/python/builtins/dict.hpp
+61
-74
rt/include/python/builtins/list.hpp
rt/include/python/builtins/list.hpp
+41
-43
rt/include/python/builtins/print.hpp
rt/include/python/builtins/print.hpp
+23
-29
rt/include/python/builtins/set.hpp
rt/include/python/builtins/set.hpp
+53
-69
rt/include/python/builtins/str.hpp
rt/include/python/builtins/str.hpp
+6
-7
rt/include/python/sys.hpp
rt/include/python/sys.hpp
+7
-7
No files found.
.clang-format
View file @
776ac174
---
Language: Cpp
BasedOnStyle: LLVM
IndentWidth: 2
UseTab: Never
---
\ No newline at end of file
UseTab: Never
\ No newline at end of file
rt/include/python/builtins.hpp
View file @
776ac174
...
...
@@ -5,51 +5,43 @@
#ifndef TYPON_BUILTINS_HPP
#define TYPON_BUILTINS_HPP
#include <ostream>
#include <iostream>
#include <optional>
#include <ostream>
#include <string>
using
namespace
std
::
literals
;
// typon_len
template
<
typename
T
>
template
<
typename
T
>
concept
PyIterator
=
requires
(
T
t
)
{
{
t
.
py_next
()
}
->
std
::
same_as
<
std
::
optional
<
T
>>
;
{
t
.
py_next
()
}
->
std
::
same_as
<
std
::
optional
<
T
>>
;
};
template
<
typename
T
>
template
<
typename
T
>
concept
PyIterable
=
requires
(
T
t
)
{
{
t
.
py_iter
()
}
->
PyIterator
;
{
t
.
py_iter
()
}
->
PyIterator
;
};
template
<
PyIterable
T
,
PyIterator
U
>
U
iter
(
const
T
&
t
)
{
return
t
.
py_iter
();
}
template
<
PyIterable
T
,
PyIterator
U
>
U
iter
(
const
T
&
t
)
{
return
t
.
py_iter
();
}
template
<
typename
T
>
template
<
typename
T
>
concept
PyLen
=
requires
(
const
T
&
t
)
{
{
t
.
py_len
()
}
->
std
::
same_as
<
size_t
>
;
{
t
.
py_len
()
}
->
std
::
same_as
<
size_t
>
;
};
template
<
PyLen
T
>
size_t
len
(
const
T
&
t
)
{
return
t
.
py_len
();
}
template
<
PyLen
T
>
size_t
len
(
const
T
&
t
)
{
return
t
.
py_len
();
}
bool
is_cpp
()
{
return
true
;
}
bool
is_cpp
()
{
return
true
;
}
#include "builtins/bool.hpp"
#include "builtins/complex.hpp"
#include "builtins/dict.hpp"
#include "builtins/list.hpp"
#include "builtins/print.hpp"
#include "builtins/range.hpp"
#include "builtins/set.hpp"
#include "builtins/str.hpp"
#endif //TYPON_BUILTINS_HPP
#endif //
TYPON_BUILTINS_HPP
rt/include/python/builtins/bool.hpp
View file @
776ac174
...
...
@@ -9,9 +9,8 @@
#include "print.hpp"
template
<
>
void
print_to
<
bool
>
(
const
bool
&
x
,
std
::
ostream
&
s
)
{
s
<<
(
x
?
"True"
:
"False"
);
template
<
>
void
print_to
<
bool
>
(
const
bool
&
x
,
std
::
ostream
&
s
)
{
s
<<
(
x
?
"True"
:
"False"
);
}
#endif //TYPON_BOOL_HPP
#endif //
TYPON_BOOL_HPP
rt/include/python/builtins/complex.hpp
View file @
776ac174
...
...
@@ -12,21 +12,16 @@
using
PyComplex
=
std
::
complex
<
double
>
;
PyComplex
operator
+
(
int
a
,
const
PyComplex
&
b
)
{
return
PyComplex
(
a
)
+
b
;
}
PyComplex
operator
+
(
int
a
,
const
PyComplex
&
b
)
{
return
PyComplex
(
a
)
+
b
;
}
PyComplex
operator
-
(
int
a
,
const
PyComplex
&
b
)
{
return
PyComplex
(
a
)
-
b
;
}
PyComplex
operator
-
(
int
a
,
const
PyComplex
&
b
)
{
return
PyComplex
(
a
)
-
b
;
}
template
<
>
void
print_to
<
PyComplex
>
(
const
PyComplex
&
x
,
std
::
ostream
&
s
)
{
if
(
x
.
real
()
==
0
)
{
s
<<
x
.
imag
()
<<
"j"
;
}
else
{
s
<<
'('
<<
x
.
real
()
<<
"+"
<<
x
.
imag
()
<<
"j)"
;
}
template
<
>
void
print_to
<
PyComplex
>
(
const
PyComplex
&
x
,
std
::
ostream
&
s
)
{
if
(
x
.
real
()
==
0
)
{
s
<<
x
.
imag
()
<<
"j"
;
}
else
{
s
<<
'('
<<
x
.
real
()
<<
"+"
<<
x
.
imag
()
<<
"j)"
;
}
}
#endif //TYPON_COMPLEX_HPP
#endif //
TYPON_COMPLEX_HPP
rt/include/python/builtins/dict.hpp
View file @
776ac174
...
...
@@ -7,93 +7,80 @@
#include <unordered_map>
template
<
typename
K
,
typename
V
>
template
<
typename
K
,
typename
V
>
class
PyDict
:
public
std
::
unordered_map
<
K
,
V
>
{
public:
PyDict
(
std
::
unordered_map
<
K
,
V
>
&&
m
)
:
std
::
unordered_map
<
K
,
V
>
(
std
::
move
(
m
))
{}
PyDict
(
std
::
unordered_map
<
K
,
V
>
&&
m
)
:
std
::
unordered_map
<
K
,
V
>
(
std
::
move
(
m
))
{}
PyDict
(
std
::
initializer_list
<
std
::
pair
<
const
K
,
V
>>
m
)
:
std
::
unordered_map
<
K
,
V
>
(
m
)
{}
PyDict
(
std
::
initializer_list
<
std
::
pair
<
const
K
,
V
>>
m
)
:
std
::
unordered_map
<
K
,
V
>
(
m
)
{}
operator
std
::
unordered_map
<
K
,
V
>
()
const
{
return
std
::
unordered_map
<
K
,
V
>
(
this
->
begin
(),
this
->
end
());
}
operator
std
::
unordered_map
<
K
,
V
>
()
const
{
return
std
::
unordered_map
<
K
,
V
>
(
this
->
begin
(),
this
->
end
());
}
operator
std
::
unordered_map
<
K
,
V
>
&
()
{
return
*
reinterpret_cast
<
std
::
unordered_map
<
K
,
V
>
*>
(
this
);
}
operator
std
::
unordered_map
<
K
,
V
>
&
()
{
return
*
reinterpret_cast
<
std
::
unordered_map
<
K
,
V
>
*>
(
this
);
}
std
::
size_t
py_len
()
const
{
return
this
->
size
();
}
std
::
size_t
py_len
()
const
{
return
this
->
size
();
}
bool
py_contains
(
const
K
&
k
)
const
{
return
this
->
find
(
k
)
!=
this
->
end
();
}
bool
py_contains
(
const
K
&
k
)
const
{
return
this
->
find
(
k
)
!=
this
->
end
();
class
iterator
{
public:
using
value_type
=
std
::
pair
<
K
,
V
>
;
using
difference_type
=
std
::
ptrdiff_t
;
using
pointer
=
std
::
pair
<
K
,
V
>
*
;
using
reference
=
std
::
pair
<
K
,
V
>
&
;
using
iterator_category
=
std
::
forward_iterator_tag
;
iterator
(
typename
std
::
unordered_map
<
K
,
V
>::
iterator
it
)
:
_it
(
it
)
{}
iterator
&
operator
++
()
{
_it
++
;
return
*
this
;
}
class
iterator
{
public:
using
value_type
=
std
::
pair
<
K
,
V
>
;
using
difference_type
=
std
::
ptrdiff_t
;
using
pointer
=
std
::
pair
<
K
,
V
>
*
;
using
reference
=
std
::
pair
<
K
,
V
>
&
;
using
iterator_category
=
std
::
forward_iterator_tag
;
iterator
(
typename
std
::
unordered_map
<
K
,
V
>::
iterator
it
)
:
_it
(
it
)
{}
iterator
&
operator
++
()
{
_it
++
;
return
*
this
;
}
iterator
operator
++
(
int
)
{
iterator
tmp
=
*
this
;
_it
++
;
return
tmp
;
}
bool
operator
==
(
const
iterator
&
rhs
)
const
{
return
_it
==
rhs
.
_it
;
}
bool
operator
!=
(
const
iterator
&
rhs
)
const
{
return
_it
!=
rhs
.
_it
;
}
const
std
::
pair
<
K
,
V
>
&
operator
*
()
const
{
return
*
_it
;
}
const
std
::
pair
<
K
,
V
>
*
operator
->
()
const
{
return
&*
_it
;
}
private:
typename
std
::
unordered_map
<
K
,
V
>::
iterator
_it
;
};
iterator
py_iter
()
const
{
return
this
->
begin
();
iterator
operator
++
(
int
)
{
iterator
tmp
=
*
this
;
_it
++
;
return
tmp
;
}
void
py_print
(
std
::
ostream
&
s
)
const
{
s
<<
'{'
;
if
(
this
->
size
()
>
0
)
{
print_to
(
this
->
begin
()
->
first
,
s
);
s
<<
": "
;
print_to
(
this
->
begin
()
->
second
,
s
);
for
(
auto
it
=
++
this
->
begin
();
it
!=
this
->
end
();
it
++
)
{
s
<<
", "
;
print_to
(
it
->
first
,
s
);
s
<<
": "
;
print_to
(
it
->
second
,
s
);
}
}
s
<<
'}'
;
bool
operator
==
(
const
iterator
&
rhs
)
const
{
return
_it
==
rhs
.
_it
;
}
bool
operator
!=
(
const
iterator
&
rhs
)
const
{
return
_it
!=
rhs
.
_it
;
}
const
std
::
pair
<
K
,
V
>
&
operator
*
()
const
{
return
*
_it
;
}
const
std
::
pair
<
K
,
V
>
*
operator
->
()
const
{
return
&*
_it
;
}
private:
typename
std
::
unordered_map
<
K
,
V
>::
iterator
_it
;
};
iterator
py_iter
()
const
{
return
this
->
begin
();
}
void
py_print
(
std
::
ostream
&
s
)
const
{
s
<<
'{'
;
if
(
this
->
size
()
>
0
)
{
print_to
(
this
->
begin
()
->
first
,
s
);
s
<<
": "
;
print_to
(
this
->
begin
()
->
second
,
s
);
for
(
auto
it
=
++
this
->
begin
();
it
!=
this
->
end
();
it
++
)
{
s
<<
", "
;
print_to
(
it
->
first
,
s
);
s
<<
": "
;
print_to
(
it
->
second
,
s
);
}
}
s
<<
'}'
;
}
};
template
<
typename
K
,
typename
V
>
template
<
typename
K
,
typename
V
>
PyDict
(
std
::
initializer_list
<
std
::
pair
<
K
,
V
>>
)
->
PyDict
<
K
,
V
>
;
#endif //TYPON_DICT_HPP
#endif // TYPON_DICT_HPP
rt/include/python/builtins/list.hpp
View file @
776ac174
...
...
@@ -5,61 +5,59 @@
#ifndef TYPON_LIST_HPP
#define TYPON_LIST_HPP
#include <vector>
#include <ostream>
#include <vector>
template
<
typename
T
>
class
PyList
:
public
std
::
vector
<
T
>
{
// TODO: Hyrum's Law, maybe consider using composition instead to not expose
// that this is a std::vector?
template
<
typename
T
>
class
PyList
:
public
std
::
vector
<
T
>
{
public:
PyList
(
std
::
vector
<
T
>
&&
v
)
:
std
::
vector
<
T
>
(
std
::
move
(
v
))
{}
PyList
(
std
::
vector
<
T
>
&&
v
)
:
std
::
vector
<
T
>
(
std
::
move
(
v
))
{}
PyList
(
std
::
initializer_list
<
T
>
&&
v
)
:
std
::
vector
<
T
>
(
std
::
move
(
v
))
{}
PyList
(
std
::
initializer_list
<
T
>
&&
v
)
:
std
::
vector
<
T
>
(
std
::
move
(
v
))
{}
operator
std
::
vector
<
T
>
()
const
{
return
std
::
vector
<
T
>
(
this
->
begin
(),
this
->
end
());
}
operator
std
::
vector
<
T
>
&
()
{
return
*
reinterpret_cast
<
std
::
vector
<
T
>
*>
(
this
);
}
operator
std
::
vector
<
T
>
()
const
{
return
std
::
vector
<
T
>
(
this
->
begin
(),
this
->
end
());
}
size_t
py_len
()
const
{
return
this
->
size
(
);
}
operator
std
::
vector
<
T
>
&
()
{
return
*
reinterpret_cast
<
std
::
vector
<
T
>
*>
(
this
);
}
void
py_print
(
std
::
ostream
&
s
)
const
{
s
<<
'['
;
if
(
this
->
size
()
>
0
)
{
print_to
(
this
->
operator
[](
0
),
s
);
for
(
size_t
i
=
1
;
i
<
this
->
size
();
i
++
)
{
s
<<
", "
;
print_to
(
this
->
operator
[](
i
),
s
);
}
}
s
<<
']'
;
}
size_t
py_len
()
const
{
return
this
->
size
();
}
PyList
<
T
>
operator
+
(
const
PyList
<
T
>
&
other
)
const
{
std
::
vector
<
T
>
v
;
v
.
reserve
(
this
->
size
()
+
other
.
size
());
v
.
insert
(
v
.
end
(),
this
->
begin
(),
this
->
end
());
v
.
insert
(
v
.
end
(),
other
.
begin
(),
other
.
end
());
return
PyList
<
T
>
(
std
::
move
(
v
));
void
py_print
(
std
::
ostream
&
s
)
const
{
s
<<
'['
;
if
(
this
->
size
()
>
0
)
{
print_to
(
this
->
operator
[](
0
),
s
);
for
(
size_t
i
=
1
;
i
<
this
->
size
();
i
++
)
{
s
<<
", "
;
print_to
(
this
->
operator
[](
i
),
s
);
}
}
s
<<
']'
;
}
PyList
<
T
>
operator
+
(
const
PyList
<
T
>
&
other
)
const
{
std
::
vector
<
T
>
v
;
v
.
reserve
(
this
->
size
()
+
other
.
size
());
v
.
insert
(
v
.
end
(),
this
->
begin
(),
this
->
end
());
v
.
insert
(
v
.
end
(),
other
.
begin
(),
other
.
end
());
return
PyList
<
T
>
(
std
::
move
(
v
));
}
PyList
<
T
>
operator
*
(
size_t
n
)
const
{
std
::
vector
<
T
>
v
;
v
.
reserve
(
this
->
size
()
*
n
);
for
(
size_t
i
=
0
;
i
<
n
;
i
++
)
{
v
.
insert
(
v
.
end
(),
this
->
begin
(),
this
->
end
());
}
return
PyList
<
T
>
(
std
::
move
(
v
));
PyList
<
T
>
operator
*
(
size_t
n
)
const
{
std
::
vector
<
T
>
v
;
v
.
reserve
(
this
->
size
()
*
n
);
for
(
size_t
i
=
0
;
i
<
n
;
i
++
)
{
v
.
insert
(
v
.
end
(),
this
->
begin
(),
this
->
end
());
}
return
PyList
<
T
>
(
std
::
move
(
v
));
}
};
template
<
typename
T
>
PyList
<
T
>
list
(
std
::
initializer_list
<
T
>
&&
v
)
{
return
PyList
<
T
>
(
std
::
move
(
v
));
template
<
typename
T
>
PyList
<
T
>
list
(
std
::
initializer_list
<
T
>
&&
v
)
{
return
PyList
<
T
>
(
std
::
move
(
v
));
}
#endif //TYPON_LIST_HPP
#endif //
TYPON_LIST_HPP
rt/include/python/builtins/print.hpp
View file @
776ac174
...
...
@@ -8,50 +8,44 @@
#include <iostream>
#include <ostream>
template
<
typename
T
>
template
<
typename
T
>
concept
Streamable
=
requires
(
const
T
&
x
,
std
::
ostream
&
s
)
{
{
s
<<
x
}
->
std
::
same_as
<
std
::
ostream
&>
;
{
s
<<
x
}
->
std
::
same_as
<
std
::
ostream
&>
;
};
template
<
Streamable
T
>
void
print_to
(
const
T
&
x
,
std
::
ostream
&
s
)
{
s
<<
x
;
}
template
<
Streamable
T
>
void
print_to
(
const
T
&
x
,
std
::
ostream
&
s
)
{
s
<<
x
;
}
template
<
typename
T
>
concept
FunctionPointer
=
std
::
is_function_v
<
T
>
or
std
::
is_member_function_pointer_v
<
T
>
or
std
::
is_function_v
<
std
::
remove_pointer_t
<
T
>>
;
template
<
typename
T
>
concept
FunctionPointer
=
std
::
is_function_v
<
T
>
or
std
::
is_member_function_pointer_v
<
T
>
or
std
::
is_function_v
<
std
::
remove_pointer_t
<
T
>>
;
template
<
Streamable
T
>
requires
(
FunctionPointer
<
T
>
)
template
<
Streamable
T
>
requires
(
FunctionPointer
<
T
>
)
void
print_to
(
const
T
&
x
,
std
::
ostream
&
s
)
{
s
<<
"<function at 0x"
<<
std
::
hex
<<
(
size_t
)
x
<<
">"
;
s
<<
"<function at 0x"
<<
std
::
hex
<<
(
size_t
)
x
<<
">"
;
}
template
<
typename
T
>
template
<
typename
T
>
concept
PyPrint
=
requires
(
const
T
&
x
,
std
::
ostream
&
s
)
{
{
x
.
py_print
(
s
)
}
->
std
::
same_as
<
void
>
;
{
x
.
py_print
(
s
)
}
->
std
::
same_as
<
void
>
;
};
template
<
PyPrint
T
>
void
print_to
(
const
T
&
x
,
std
::
ostream
&
s
)
{
x
.
py_print
(
s
);
template
<
PyPrint
T
>
void
print_to
(
const
T
&
x
,
std
::
ostream
&
s
)
{
x
.
py_print
(
s
);
}
template
<
typename
T
>
template
<
typename
T
>
concept
Printable
=
requires
(
const
T
&
x
,
std
::
ostream
&
s
)
{
{
print_to
(
x
,
s
)
}
->
std
::
same_as
<
void
>
;
{
print_to
(
x
,
s
)
}
->
std
::
same_as
<
void
>
;
};
template
<
Printable
T
,
Printable
...
Args
>
void
print
(
T
const
&
head
,
Args
const
&
...
args
)
{
print_to
(
head
,
std
::
cout
);
(((
std
::
cout
<<
' '
),
print_to
(
args
,
std
::
cout
)),
...);
std
::
cout
<<
'\n'
;
template
<
Printable
T
,
Printable
...
Args
>
void
print
(
T
const
&
head
,
Args
const
&
...
args
)
{
print_to
(
head
,
std
::
cout
);
(((
std
::
cout
<<
' '
),
print_to
(
args
,
std
::
cout
)),
...);
std
::
cout
<<
'\n'
;
}
void
print
()
{
std
::
cout
<<
'\n'
;
}
#endif //TYPON_PRINT_HPP
void
print
()
{
std
::
cout
<<
'\n'
;
}
#endif // TYPON_PRINT_HPP
rt/include/python/builtins/set.hpp
View file @
776ac174
...
...
@@ -7,86 +7,70 @@
#include <unordered_set>
template
<
typename
T
>
class
PySet
:
public
std
::
unordered_set
<
T
>
{
template
<
typename
T
>
class
PySet
:
public
std
::
unordered_set
<
T
>
{
public:
PySet
(
std
::
unordered_set
<
T
>
&&
s
)
:
std
::
unordered_set
<
T
>
(
std
::
move
(
s
))
{}
PySet
(
std
::
unordered_set
<
T
>
&&
s
)
:
std
::
unordered_set
<
T
>
(
std
::
move
(
s
))
{}
PySet
(
std
::
initializer_list
<
T
>
&&
s
)
:
std
::
unordered_set
<
T
>
(
std
::
move
(
s
))
{}
PySet
(
std
::
initializer_list
<
T
>
&&
s
)
:
std
::
unordered_set
<
T
>
(
std
::
move
(
s
))
{}
operator
std
::
unordered_set
<
T
>
()
const
{
return
std
::
unordered_set
<
T
>
(
this
->
begin
(),
this
->
end
());
}
operator
std
::
unordered_set
<
T
>
()
const
{
return
std
::
unordered_set
<
T
>
(
this
->
begin
(),
this
->
end
());
}
std
::
size_t
py_len
()
const
{
return
this
->
size
();
}
std
::
size_t
py_len
()
const
{
return
this
->
size
();
}
bool
py_contains
(
const
T
&
t
)
const
{
return
this
->
find
(
t
)
!=
this
->
end
();
}
bool
py_contains
(
const
T
&
t
)
const
{
return
this
->
find
(
t
)
!=
this
->
end
();
class
iterator
{
public:
using
value_type
=
T
;
using
difference_type
=
std
::
ptrdiff_t
;
using
pointer
=
T
*
;
using
reference
=
T
&
;
using
iterator_category
=
std
::
forward_iterator_tag
;
iterator
(
typename
std
::
unordered_set
<
T
>::
iterator
it
)
:
_it
(
it
)
{}
iterator
&
operator
++
()
{
_it
++
;
return
*
this
;
}
class
iterator
{
public:
using
value_type
=
T
;
using
difference_type
=
std
::
ptrdiff_t
;
using
pointer
=
T
*
;
using
reference
=
T
&
;
using
iterator_category
=
std
::
forward_iterator_tag
;
iterator
(
typename
std
::
unordered_set
<
T
>::
iterator
it
)
:
_it
(
it
)
{}
iterator
&
operator
++
()
{
_it
++
;
return
*
this
;
}
iterator
operator
++
(
int
)
{
iterator
tmp
=
*
this
;
_it
++
;
return
tmp
;
}
bool
operator
==
(
const
iterator
&
rhs
)
const
{
return
_it
==
rhs
.
_it
;
}
bool
operator
!=
(
const
iterator
&
rhs
)
const
{
return
_it
!=
rhs
.
_it
;
}
const
T
&
operator
*
()
const
{
return
*
_it
;
}
const
T
*
operator
->
()
const
{
return
&*
_it
;
}
private:
typename
std
::
unordered_set
<
T
>::
iterator
_it
;
};
iterator
py_iter
()
const
{
return
this
->
begin
();
iterator
operator
++
(
int
)
{
iterator
tmp
=
*
this
;
_it
++
;
return
tmp
;
}
void
py_print
(
std
::
ostream
&
s
)
const
{
s
<<
'{'
;
if
(
this
->
size
()
>
0
)
{
print_to
(
*
this
->
begin
(),
s
);
for
(
auto
it
=
++
this
->
begin
();
it
!=
this
->
end
();
it
++
)
{
s
<<
", "
;
print_to
(
*
it
,
s
);
}
}
s
<<
'}'
;
bool
operator
==
(
const
iterator
&
rhs
)
const
{
return
_it
==
rhs
.
_it
;
}
bool
operator
!=
(
const
iterator
&
rhs
)
const
{
return
_it
!=
rhs
.
_it
;
}
const
T
&
operator
*
()
const
{
return
*
_it
;
}
const
T
*
operator
->
()
const
{
return
&*
_it
;
}
private:
typename
std
::
unordered_set
<
T
>::
iterator
_it
;
};
iterator
py_iter
()
const
{
return
this
->
begin
();
}
void
py_print
(
std
::
ostream
&
s
)
const
{
s
<<
'{'
;
if
(
this
->
size
()
>
0
)
{
print_to
(
*
this
->
begin
(),
s
);
for
(
auto
it
=
++
this
->
begin
();
it
!=
this
->
end
();
it
++
)
{
s
<<
", "
;
print_to
(
*
it
,
s
);
}
}
s
<<
'}'
;
}
};
template
<
typename
T
>
PySet
<
T
>
set
(
std
::
initializer_list
<
T
>
&&
s
)
{
return
PySet
<
T
>
(
std
::
move
(
s
));
template
<
typename
T
>
PySet
<
T
>
set
(
std
::
initializer_list
<
T
>
&&
s
)
{
return
PySet
<
T
>
(
std
::
move
(
s
));
}
#endif //TYPON_SET_HPP
#endif //
TYPON_SET_HPP
rt/include/python/builtins/str.hpp
View file @
776ac174
...
...
@@ -5,16 +5,15 @@
#ifndef TYPON_STR_HPP
#define TYPON_STR_HPP
#include <string>
#include <sstream>
#include <string>
using
namespace
std
::
literals
;
template
<
typename
T
>
std
::
string
str
(
const
T
&
x
)
{
std
::
stringstream
s
;
print_to
(
x
,
s
);
return
s
.
str
();
template
<
typename
T
>
std
::
string
str
(
const
T
&
x
)
{
std
::
stringstream
s
;
print_to
(
x
,
s
);
return
s
.
str
();
}
#endif //TYPON_STR_HPP
#endif //
TYPON_STR_HPP
rt/include/python/sys.hpp
View file @
776ac174
...
...
@@ -8,11 +8,11 @@
#include <iostream>
namespace
py_sys
{
struct
sys_t
{
static
constexpr
auto
&
stdin
=
std
::
cin
;
static
constexpr
auto
&
stdout
=
std
::
cout
;
static
constexpr
auto
&
stderr
=
std
::
cerr
;
}
all
;
}
struct
sys_t
{
static
constexpr
auto
&
stdin
=
std
::
cin
;
static
constexpr
auto
&
stdout
=
std
::
cout
;
static
constexpr
auto
&
stderr
=
std
::
cerr
;
}
all
;
}
// namespace py_sys
#endif //TYPON_SYS_HPP
#endif //
TYPON_SYS_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