Skip to content

AStaticVector#

Vector-like container up to maxSize elements inplace.

Header:#include <AUI/Common/AStaticVector.h>
CMake:aui_link(my_target PUBLIC aui::core)

Detailed Description#

Vector-like container optimized for the case when it contains up to maxSize in place, avoiding dynamic allocation. AStaticVector could not contain more than maxSize elements.

Public Methods#

contains#


bool AStaticVector::contains(const StoredType& value)
Returns
true if container contains an element, false otherwise.

first#


StoredType& AStaticVector::first()
Returns
the first element.
Sneaky assertions
Container is not empty.

Examples#

examples/ui/contacts/src/view/ContactDetailsView.cpp

AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.

namespace {
_<AView> profilePhoto(const _<Contact>& contact) {
    return Centered {
        Label {} & contact->displayName.readProjected([](const AString& s) {
            return s.empty() ? "?" : AString(1, s.first()).uppercase();
        }) AUI_WITH_STYLE { Opacity(0.5f), FontSize { 32_dp } },
    } AUI_WITH_STYLE {
        FixedSize { 64_dp },
        BorderRadius { 32_dp },
        BackgroundGradient { AColor::GRAY.lighter(0.5f), AColor::GRAY, 163_deg },
examples/7guis/cells/src/AST.cpp

7GUIs Cells - Spreadsheet processor (Excel).

            // should assign it to some operator
            for (const auto& o : binaryOperators | ranges::views::reverse) {
                if (o.op->right == nullptr) {
                    o.op->right = std::move(temporaryValue);
                    AUI_ASSERT(binaryOperators.first().owning != nullptr);
                    return std::move(binaryOperators.first().owning);
                }
            }
            throw AException {};
        }
examples/7guis/cells/src/main.cpp

7GUIs Cells - Spreadsheet processor (Excel).

                      [](const AString& v) -> _<AView> { return Label { "{}"_format(v) }; },
                      [](const formula::Range& v) -> _<AView> { return Label { "#RANGE?" }; },
                    },
                    v));
            connect(getViews().first()->clicked, me::inflateEditor);
        });
    }

    void inflateEditor() {
        mState->currentExpression = mCell.expression;

const StoredType& AStaticVector::first()
Returns
the first element.
Sneaky assertions
Container is not empty.

Examples#

examples/ui/contacts/src/view/ContactDetailsView.cpp

AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.

namespace {
_<AView> profilePhoto(const _<Contact>& contact) {
    return Centered {
        Label {} & contact->displayName.readProjected([](const AString& s) {
            return s.empty() ? "?" : AString(1, s.first()).uppercase();
        }) AUI_WITH_STYLE { Opacity(0.5f), FontSize { 32_dp } },
    } AUI_WITH_STYLE {
        FixedSize { 64_dp },
        BorderRadius { 32_dp },
        BackgroundGradient { AColor::GRAY.lighter(0.5f), AColor::GRAY, 163_deg },
examples/7guis/cells/src/AST.cpp

7GUIs Cells - Spreadsheet processor (Excel).

            // should assign it to some operator
            for (const auto& o : binaryOperators | ranges::views::reverse) {
                if (o.op->right == nullptr) {
                    o.op->right = std::move(temporaryValue);
                    AUI_ASSERT(binaryOperators.first().owning != nullptr);
                    return std::move(binaryOperators.first().owning);
                }
            }
            throw AException {};
        }
examples/7guis/cells/src/main.cpp

7GUIs Cells - Spreadsheet processor (Excel).

                      [](const AString& v) -> _<AView> { return Label { "{}"_format(v) }; },
                      [](const formula::Range& v) -> _<AView> { return Label { "#RANGE?" }; },
                    },
                    v));
            connect(getViews().first()->clicked, me::inflateEditor);
        });
    }

    void inflateEditor() {
        mState->currentExpression = mCell.expression;

fromRange#


template<aui::incrementable Iterator, aui::invocable<decltype(* std::declval<Iterator>())> UnaryOperation >
static auto AStaticVector::fromRange(aui::range<Iterator> range, UnaryOperation&& transformer)

Constructs a new vector of transformed items of the range.

Arguments
range
items to transform from.
transformer
transformer function.
Returns
A new vector.

indexOf#


AOptional<size_t> AStaticVector::indexOf(const StoredType& value)
Arguments
value
element to find.
Returns
index of the specified element. If element is not found, std::nullopt is returned.

insertAll#


template<typename OtherContainer >
iterator AStaticVector::insertAll(const OtherContainer& c)
Arguments
c
other container
Returns
iterator pointing to the first element inserted.

Inserts all values of the specified container to the end.


template<typename OtherContainer >
iterator AStaticVector::insertAll(OtherContainer&& c)
Arguments
c
other container
Returns
iterator pointing to the first element inserted.

Inserts all values of the specified container to the end.


template<typename OtherContainer >
iterator AStaticVector::insertAll(iterator at, const OtherContainer& c)
Arguments
at
position to insert at.
c
other container
Returns
iterator pointing to the first element inserted.

Inserts all values of the specified container.


template<typename OtherContainer >
iterator AStaticVector::insertAll(iterator at, OtherContainer&& c)
Arguments
at
position to insert at.
c
other container
Returns
iterator pointing to the first element inserted.

Inserts all values of the specified container.

isSubsetOf#


template<typename OtherContainer >
bool AStaticVector::isSubsetOf(const OtherContainer& c)
Returns
true if c container is a subset of this container, false otherwise.

last#


StoredType& AStaticVector::last()
Returns
the last element.
Sneaky assertions
Container is not empty.

Examples#

examples/7guis/cells/src/AST.cpp

7GUIs Cells - Spreadsheet processor (Excel).

            if (temporaryValue) {
                throw AException("SYNTAX");
            }
            if (!binaryOperators.empty()) {
                if (binaryOperators.last().op->right) {
                    throw AException {};
                }
                binaryOperators.last().op->right = std::move(node);
                return;
            }

const StoredType& AStaticVector::last()
Returns
the last element.
Sneaky assertions
Container is not empty.

Examples#

examples/7guis/cells/src/AST.cpp

7GUIs Cells - Spreadsheet processor (Excel).

            if (temporaryValue) {
                throw AException("SYNTAX");
            }
            if (!binaryOperators.empty()) {
                if (binaryOperators.last().op->right) {
                    throw AException {};
                }
                binaryOperators.last().op->right = std::move(node);
                return;
            }

removeAll#


void AStaticVector::removeAll(const StoredType& item)
Arguments
item
element to remove.

Removes all occurrences of item.

removeAt#


void AStaticVector::removeAt(size_t index)
Arguments
index
index of the element.

Removes element at the specified index.

Sneaky assertions
index points to the existing element.

removeFirst#


void AStaticVector::removeFirst(const StoredType& item)
Arguments
item
element to remove.

Removes first occurrence of item.

removeIf#


template<typename Predicate >
void AStaticVector::removeIf(Predicate&& predicate)
Arguments
predicate
predicate

Removes element if predicate(container[i]) == true.