Skip to content

Commit 5d9c2ad

Browse files
committed
added spans
also lots of misc fixes + refactors
1 parent 6e1cb2d commit 5d9c2ad

38 files changed

+3600
-2126
lines changed

CHANGELOG.md

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
# Changelog
22

3-
## Unreleased
4-
5-
- Fixed `swap_columns` fast-path breaking `data()`
6-
- Used more CRTP mixins in generated classes
3+
## v0.6.0
4+
5+
- Fixed `swap_columns()` fast-path breaking `data()`
6+
- Added spans
7+
- Added `span`
8+
- Added `is_span<>`
9+
- Added `table::subspan()` and `table::const_subspan()`
10+
- Added `span_type<>` and `const_span_type<>`
11+
- Added `soa_type<>`
12+
- Added `const_iterator_type<>`
13+
- Added `const_row_type<>`
14+
- Added `column_indices<>`
15+
- Added `soagen::for_each_column()`
16+
- Added `row::for_each_column()`
17+
- Added generic names `first`, `second`, ..., `sixteenth` for unnamed columns 0-15
18+
- Added const propagation to `soagen::row` member functions
719
- Binary size improvements
20+
- Documentation improvements
821

922
## v0.5.0
1023

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# soagen
22

3-
Struct-of-Arrays generator for C++ projects.
3+
Struct-of-Arrays for C++.
44

55
[![Sponsor](docs/images/badge-sponsor.svg)][sponsor]
66
[![Gitter](docs/images/badge-gitter.svg)][gitter]

docs/pages/intro.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
@mainpage soagen: A Structure-of-Arrays generator for C++
1+
@mainpage soagen: Structure-of-Arrays for C++
22

33
@tableofcontents
44

55
@section intro_tldr TL;DR
66

77
The leading section of this page is an overview of what [Structures-of-Arrays (SoA)](https://en.wikipedia.org/wiki/AoS_and_SoA)
88
are, what problems they solve, and the annoyances of working with them in C++. Following that is an overview of
9-
**soagen** - a new Structure-Of-Arrays generator and library for C++17 and later.
9+
**soagen** - a new Structure-Of-Arrays library and generator for C++17 and later.
1010

1111
@inline_success Skip to @ref intro_introducing_soagen if you already know all about SoA and want to go
1212
straight to learning about **soagen** instead.
@@ -34,10 +34,10 @@ struct employee
3434
};
3535
```
3636

37-
And elsewhere in the program you'd almost certainly find this:
37+
And elsewhere in the program you'd almost certainly find something like this:
3838

3939
```cpp
40-
std::vector<employee> employees;
40+
std::vector<employee> all_employees;
4141
```
4242

4343
This paradigm is broadly called [Array-of-Structures](https://en.wikipedia.org/wiki/AoS_and_SoA) \(AoS\).
@@ -102,7 +102,7 @@ struct entity
102102
As before, lets have a look at what an array of these would look like in memory:
103103

104104
```cpp
105-
std::vector<entity> entities;
105+
std::vector<entity> all_entities;
106106
```
107107

108108
@parblock
@@ -263,8 +263,8 @@ SoAgen, Soagen, SOAgen, whatever.</i>
263263

264264
@subsection intro_getting_started_prerequisites Prerequisites
265265

266-
- Using the generator: Python 3.9 or higher
267266
- Using the C++ library and/or generated code: C++17 or later
267+
- Using the generator: Python 3.9 or higher
268268

269269
@subsection intro_getting_started_generator Installing soagen
270270

docs/pages/schema.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ individal tables in your struct's `static_variables`, e.g.:
492492
```toml
493493
[structs.particles]
494494
static_variables = [
495-
{ name = '...', type = '...', ... }
495+
{ name = 'default_mass', type = 'float', ... }
496496
]
497497
```
498498

@@ -626,7 +626,7 @@ tables in your struct's `variables`, e.g.:
626626
```toml
627627
[structs.particles]
628628
variables = [
629-
{ name = '...', type = '...', ... }
629+
{ name = 'mass', type = 'float', ... }
630630
]
631631
```
632632

docs/poxy.toml

+6-18
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ paths = ['images']
5454
macros = ['SOAGEN_[A-Z0-9_]+?']
5555
types = [
5656
'employee',
57+
'employees',
5758
'quaternion',
58-
'game::entities',
59+
'entity',
5960
'entities',
6061
'entities::columns',
62+
'game::entities',
6163
'emplacer',
62-
'game::raw_entities',
63-
'raw_entities',
6464
]
6565
namespaces = ['game']
6666

@@ -71,21 +71,9 @@ namespaces = ['game']
7171
[autolinks]
7272
'soagen::iterators?' = 'classsoagen_1_1iterator.html'
7373
'soagen::rows?' = 'structsoagen_1_1row.html'
74-
'(?:soagen::)emplacers?' = 'structsoagen_1_1emplacer.html'
74+
'(?:soagen::)?emplacers?' = 'structsoagen_1_1emplacer.html'
7575
'soagen::tables?' = 'classsoagen_1_1table.html'
7676
'CRTP' = 'https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern'
7777

78-
#[implementation_headers]
79-
#'soagen.hpp' = [
80-
# 'allocator.hpp',
81-
# 'column_traits.hpp',
82-
# 'iterator.hpp',
83-
# 'core.hpp',
84-
# 'mixins.hpp',
85-
# 'row.hpp',
86-
# 'table_traits.hpp',
87-
# 'table.hpp',
88-
# # 'generated/compressed_pair.hpp',
89-
# 'generated/functions.hpp',
90-
# 'generated/preprocessor.hpp',
91-
#]
78+
[macros]
79+
'SOAGEN_COLUMN(...)' = ''

examples/entities.hpp

+46-19
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ namespace soagen::detail
145145
SOAGEN_MAKE_NAMED_COLUMN(soagen::examples::entities, 2, pos);
146146
SOAGEN_MAKE_NAMED_COLUMN(soagen::examples::entities, 3, orient);
147147

148+
template <>
149+
struct is_soa_<soagen::examples::entities> : std::true_type
150+
{};
151+
148152
template <>
149153
struct table_traits_type_<soagen::examples::entities>
150154
{
@@ -166,10 +170,6 @@ namespace soagen::detail
166170
{
167171
using type = table<table_traits_type<soagen::examples::entities>, allocator_type<soagen::examples::entities>>;
168172
};
169-
170-
template <>
171-
struct is_soa_<soagen::examples::entities> : std::true_type
172-
{};
173173
}
174174

175175
// clang-format on
@@ -208,6 +208,7 @@ namespace soagen::examples
208208
public soagen::mixins::columns<entities>,
209209
public soagen::mixins::rows<entities>,
210210
public soagen::mixins::iterators<entities>,
211+
public soagen::mixins::spans<entities>,
211212
public soagen::mixins::swappable<entities>)
212213
{
213214
public:
@@ -240,12 +241,21 @@ namespace soagen::examples
240241
/// @brief Row iterators returned by iterator functions.
241242
using iterator = soagen::iterator_type<entities>;
242243

243-
/// @brief Row iterators returned by const-qualified iterator functions.
244-
using const_iterator = soagen::iterator_type<const entities>;
245-
246244
/// @brief Row iterators returned by rvalue-qualified iterator functions.
247245
using rvalue_iterator = soagen::iterator_type<entities&&>;
248246

247+
/// @brief Row iterators returned by const-qualified iterator functions.
248+
using const_iterator = soagen::const_iterator_type<entities>;
249+
250+
/// @brief Regular (lvalue-qualified) span type.
251+
using span_type = soagen::span_type<entities>;
252+
253+
/// @brief Rvalue-qualified span type.
254+
using rvalue_span_type = soagen::span_type<entities&&>;
255+
256+
/// @brief Const-qualified span type.
257+
using const_span_type = soagen::const_span_type<entities>;
258+
249259
/// @brief Regular (lvalue-qualified) row type used by this class.
250260
using row_type = soagen::row_type<entities>;
251261

@@ -332,7 +342,7 @@ namespace soagen::examples
332342
return table_.get_allocator();
333343
}
334344

335-
/// @name Underlying table access
345+
/// @name Underlying table
336346
/// @{
337347

338348
/// @brief Returns an lvalue reference to the underlying soagen::table.
@@ -358,21 +368,21 @@ namespace soagen::examples
358368

359369
/// @brief Returns an lvalue reference to the underlying soagen::table.
360370
SOAGEN_PURE_INLINE_GETTER
361-
explicit constexpr operator table_type&() & noexcept
371+
explicit constexpr operator table_type&() noexcept
362372
{
363373
return table_;
364374
}
365375

366376
/// @brief Returns an rvalue reference to the underlying soagen::table.
367377
SOAGEN_PURE_INLINE_GETTER
368-
explicit constexpr operator table_type&&() && noexcept
378+
explicit constexpr operator table_type&&() noexcept
369379
{
370380
return static_cast<table_type&&>(table_);
371381
}
372382

373383
/// @brief Returns a const lvalue reference to the underlying soagen::table.
374384
SOAGEN_PURE_INLINE_GETTER
375-
explicit constexpr operator const table_type&() const& noexcept
385+
explicit constexpr operator const table_type&() const noexcept
376386
{
377387
return table_;
378388
}
@@ -451,7 +461,7 @@ namespace soagen::examples
451461
noexcept(soagen::has_nothrow_unordered_erase_member<table_type>)
452462
{
453463
if (auto moved_pos = table_.unordered_erase(static_cast<size_type>(pos)); moved_pos)
454-
return iterator{ table_, static_cast<difference_type>(*moved_pos) };
464+
return iterator{ *this, static_cast<difference_type>(*moved_pos) };
455465
return {};
456466
}
457467

@@ -490,7 +500,7 @@ namespace soagen::examples
490500
noexcept(soagen::has_nothrow_unordered_erase_member<table_type>)
491501
{
492502
if (auto moved_pos = table_.unordered_erase(static_cast<size_type>(pos)); moved_pos)
493-
return const_iterator{ table_, static_cast<difference_type>(*moved_pos) };
503+
return const_iterator{ *this, static_cast<difference_type>(*moved_pos) };
494504
return {};
495505
}
496506

@@ -875,7 +885,7 @@ namespace soagen::examples
875885

876886
/// @}
877887

878-
/// @name Column access
888+
/// @name Columns
879889
/// @{
880890

881891
/// @brief Returns a pointer to the elements of a specific column.
@@ -1060,23 +1070,23 @@ namespace soagen::examples
10601070

10611071
/// @brief Returns an iterator to the first row in the table.
10621072
template <auto... Columns>
1063-
constexpr soagen::iterator_type<const entities, Columns...> begin() const& noexcept;
1073+
constexpr soagen::const_iterator_type<entities, Columns...> begin() const& noexcept;
10641074

10651075
/// @brief Returns an iterator to one-past-the-last row in the table.
10661076
template <auto... Columns>
1067-
constexpr soagen::iterator_type<const entities, Columns...> end() const& noexcept;
1077+
constexpr soagen::const_iterator_type<entities, Columns...> end() const& noexcept;
10681078

10691079
/// @brief Returns an iterator to the first row in the table.
10701080
template <auto... Columns>
1071-
constexpr soagen::iterator_type<const entities, Columns...> cbegin() const noexcept;
1081+
constexpr soagen::const_iterator_type<entities, Columns...> cbegin() const noexcept;
10721082

10731083
/// @brief Returns an iterator to one-past-the-last row in the table.
10741084
template <auto... Columns>
1075-
constexpr soagen::iterator_type<const entities, Columns...> cend() const noexcept;
1085+
constexpr soagen::const_iterator_type<entities, Columns...> cend() const noexcept;
10761086

10771087
/// @}
10781088

1079-
/// @name Row access
1089+
/// @name Rows
10801090
/// @{
10811091

10821092
/// @brief Returns the row at the given index.
@@ -1141,6 +1151,23 @@ namespace soagen::examples
11411151

11421152
/// @}
11431153

1154+
/// @name Spans
1155+
/// @{
1156+
1157+
/// @brief Returns a span of (some part of) the table.
1158+
span_type subspan(size_type start, size_type count = static_cast<size_type>(-1)) & noexcept;
1159+
1160+
/// @brief Returns an rvalue-qualified span of (some part of) the table.
1161+
rvalue_span_type subspan(size_type start, size_type count = static_cast<size_type>(-1)) && noexcept;
1162+
1163+
/// @brief Returns a const-qualified span of (some part of) the table.
1164+
const_span_type subspan(size_type start, size_type count = static_cast<size_type>(-1)) const& noexcept;
1165+
1166+
/// @brief Returns a const-qualified span of (some part of) the table.
1167+
const_span_type const_subspan(size_type start, size_type count = static_cast<size_type>(-1)) const noexcept;
1168+
1169+
/// @}
1170+
11441171
#endif
11451172
};
11461173

0 commit comments

Comments
 (0)