Skip to content

Commit

Permalink
added rvalue_iterators switch
Browse files Browse the repository at this point in the history
  • Loading branch information
marzer committed Jul 26, 2023
1 parent e915db1 commit ab1bad0
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/soagen/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Struct(Configurable):
Optional(r'swappable', default=True): bool,
Optional(r'iterators', default=True): bool,
Optional(r'reverse_iterators', default=False): bool,
Optional(r'rvalue_iterators', default=True): bool,
Optional(r'column_providers', default=True): bool,
Optional(r'stripes', default=list): [object],
Optional(r'spans', default=True): bool,
Expand Down Expand Up @@ -333,12 +334,17 @@ def doxygen(s: str) -> str:
{doxygen(r"@brief Row iterators returned by const-qualified iterator functions.")}
using const_iterator = soagen::iterator_type<const {self.name}&>;
{doxygen(r"@brief Row iterators returned by rvalue-qualified iterator functions.")}
using rvalue_iterator = soagen::iterator_type<{self.name}&&>;
'''
)

if self.rvalue_iterators:
o(
rf'''
{doxygen(r"@brief Row iterators returned by rvalue-qualified iterator functions.")}
using rvalue_iterator = soagen::iterator_type<{self.name}&&>;
'''
)

if self.iterators and self.reverse_iterators:
o(
rf'''
Expand All @@ -348,10 +354,16 @@ def doxygen(s: str) -> str:
{doxygen(r"@brief Reverse const lvalue row iterator.")}
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
{doxygen(r"@brief Reverse rvalue row iterator.")}
using rvalue_reverse_iterator = std::reverse_iterator<rvalue_iterator>;
'''
)
if self.rvalue_iterators:
o(
rf'''
{doxygen(r"@brief Reverse rvalue row iterator.")}
using rvalue_reverse_iterator = std::reverse_iterator<rvalue_iterator>;
'''
)

o(
rf'''
Expand Down Expand Up @@ -1165,6 +1177,8 @@ def doxygen(s: str) -> str:
for const, ref in (('', '&'), ('', '&&'), ('const ', '&')):
if 'c' in func and (not const or ref == '&&'):
continue
if ref == '&&' and not self.rvalue_iterators:
continue

move_l = 'std::move(' if ref == '&&' else ''
move_r = ')' if ref == '&&' else ''
Expand All @@ -1187,15 +1201,15 @@ def doxygen(s: str) -> str:
{doxygen(rf"""@brief Returns {an} iterator to the {first} row in the table.""")}
template <size_type... Columns>
SOAGEN_PURE_INLINE_GETTER
constexpr {iterator} {func}begin() {const}{ref} noexcept
constexpr {iterator} {func}begin() {const}{ref if self.rvalue_iterators else ''} noexcept
{{
return {{ {begin} }};
}}
{doxygen(rf"""@brief Returns {an} iterator to one-{past}-the-{last} row in the table.""")}
template <size_type... Columns>
SOAGEN_PURE_INLINE_GETTER
constexpr {iterator} {func}end() {const}{ref} noexcept
constexpr {iterator} {func}end() {const}{ref if self.rvalue_iterators else ''} noexcept
{{
return {{ {end} }};
}}
Expand Down

0 comments on commit ab1bad0

Please sign in to comment.