Skip to content

Consider using flags to customize ArrayOutputMixin #455

@arcondello

Description

@arcondello

E.g., imagine that you want to disallow an ArrayNode from ever being dynamic. It might be nice to be able to specify that as a template argument to ArrayOutputMixin. This would allow is to combine different flags like the one we already added to ScalarOutputMixin in #271.

Something like

enum class ArrayMixinFlags {
    // default is sometimes dynamic
    AlwaysDynamic = 1 << 0,
    NeverDynamic = 1 << 1,

    // default is not to provide a state implementation
    ProvideState = 1 << 2,
};

template <class Base, ArrayMixinFlags Flags = 0>
class ArrayOutputMixin : public Base {
    template <std::ranges::sized_range Range>
    explicit ArrayOutputMixin(Range&& shape)
            : ndim_(shape.size()), shape_(make_shape(std::forward<Range>(shape))) {
        if constexpr (Flags && ArrayMixinFlags::NeverDynamic) {
            // throw an error if dynamic
        }
    }

    ...
};


class NeverDynamicNode : public ArrayOutputMixin<ArrayNode, ArrayMixinFlags::NeverDynamic> {
    ...
};

class NeverDynamicAndDefaultStateNode : public ArrayOutputMixin<ArrayNode, ArrayMixinFlags::NeverDynamic | ArrayMixinFlags::ProvideState> {
    ...
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions