aui::any_view#
RTTI-wrapped range.
| Header: | #include <AUI/Traits/any_view.h> |
| CMake: | aui_link(my_target PUBLIC aui::core) |
Detailed Description#
Experimental Feature
This API is experimental. Experimental APIs are likely to contain bugs, might be changed or removed in the future.
aui::any_view is a dynamic range class that mimics the behavior of C++20 ranges/range-v3 using type-erased
interfaces. It allows for the creation of runtime-checked, polymorphic ranges with input iterators.
Alternative implementation of ranges::views::any_view.
The general idea is to preserve lazy nature of C++20 ranges/range-v3 and flexibility between compilation modules.
Keep in mind that type erasure can lead to performance overhead due to dynamic dispatch.
aui::any_view initialized with an lvalue reference will contain a reference to the container; thus the container
can be modified.
aui::any_view initialized with an rvalue reference will move the container into itself; thus it acquires
ownership.
Using aui::any_view::iterator acquired before modification of the referenced container may lead to undefined
behaviour; it all depends on the referenced container.
aui::any_view follows the same principle as std::function for functors.
Public Types#
iterator#
struct aui::any_view::iterator
Empty structure.
Public Methods#
begin#
- Returns
- polymorphic begin iterator.
Examples:
examples/7guis/cells/src/AST.cpp
7GUIs Cells — Spreadsheet processor (Excel).
}
}
if (!binaryOperators.empty()) {
auto root = std::min_element(
binaryOperators.begin(), binaryOperators.end(),
[](const BinaryOperatorAndItsPriority& lhs, const BinaryOperatorAndItsPriority& rhs) {
return lhs.priority < rhs.priority;
});
auto out = std::make_unique<T>();
AUI_ASSERT(root->owning != nullptr);
examples/7guis/cells/src/Cell.cpp
7GUIs Cells — Spreadsheet processor (Excel).
}
glm::uvec2 Cell::fromName(const AString& name) {
glm::uvec2 out{UNDEFINED};
auto it = name.begin();
for (;it != name.end() && 'A' <= *it && *it <= 'Z'; ++it) {
if (out.x == UNDEFINED) { out.x = 0; }
out.x *= 26;
out.x += *it - 'A';
}
examples/7guis/circle_drawer/src/main.cpp
7GUIs Circle Drawer — Undo, redo, dialog control.
examples/app/minesweeper/src/NewGameWindow.h
Minesweeper Game — Minesweeper game implementation driven by ass.
_<ALabel> mDifficultyLabel;
void updateMinesMax();
void updateDifficultyLabel();
void begin();
};
examples/app/minesweeper/src/NewGameWindow.cpp
Minesweeper Game — Minesweeper game implementation driven by ass.
Horizontal {
_new<ASpacerExpanding>(),
_new<AButton>("Start game") AUI_LET {
it->setDefault();
connect(it->clicked, me::begin);
},
_new<AButton>("Cancel").connect(&AButton::clicked, me::close),
} AUI_OVERRIDE_STYLE { LayoutSpacing { 4_dp } },
} AUI_OVERRIDE_STYLE { LayoutSpacing { 4_dp } });
examples/ui/contacts/src/main.cpp
AUI Contacts — Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
_<AView> indexedList() {
return AUI_DECLARATIVE_FOR(group, *mContacts | ranges::views::chunk_by([](const _<Contact>& lhs, const _<Contact>& rhs) {
return groupLetter(lhs->displayName) == groupLetter(rhs->displayName);
}), AVerticalLayout) {
auto firstContact = *ranges::begin(group);
auto firstLetter = groupLetter(firstContact->displayName);
ALogger::info("Test") << "Computing view for group " << AString(1, firstLetter);
return Vertical {
Label { firstLetter } AUI_OVERRIDE_STYLE {
Opacity(0.5f),
end#
- Returns
- polymorphic end iterator.
Examples:
examples/app/notes/src/main.cpp
Notes App — Note taking app that demonstrates usage of AListModel, AProperty, user data saving and loading.
examples/app/game_of_life/src/main.cpp
Game of Life — Game of Life implementation that uses advanced large dynamic data rendering techniques such as ITexture, AImage to be GPU friendly. The computation is performed in AThreadPool.