Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make mode() a runtime decision #1436

Closed
5 tasks
rrahn opened this issue Dec 17, 2019 · 3 comments · Fixed by #1853
Closed
5 tasks

Make mode() a runtime decision #1436

rrahn opened this issue Dec 17, 2019 · 3 comments · Fixed by #1853
Assignees

Comments

@rrahn
Copy link
Contributor

rrahn commented Dec 17, 2019

(user feedback)

Make it a hybrid configuration, i.e. it can be either set at runtime or at compile time if known already.
See https://github.com/seqan/seqan3/blob/master/include/seqan3/alignment/configuration/align_config_aligned_ends.hpp as a reference to implement both using almost the same interface.
Make the configuration options enums and then in addition define integral_constant values from the enums. Then the config can be called from the enum and the enum can be changed at runtime, or if the configuration is already known one can use the variable with the encoded enum.

enum struct find : uint8_t
{
    best
};
inline constexpr std::integral_constant<find, find::best> find_best{};
...
search_cfg::mode(find::best)  // uses enum
search_cfg::mode(find_best)  // uses static type info
  • think about a better name for find
  • adapt the configuration to use enum
  • tests
  • adapt algorithm config
  • adapt docu (API, tutorial)
@h-2
Copy link
Member

h-2 commented Jan 2, 2020

I think I figured out a way we can have nice hybrid options. Have a look at this:

enum class select
{
    all,
    all_best,
    best
};

template <select s>
struct static_conf
{
    static constexpr select value = s;
};

struct dynamic_conf
{
    select value;
};

constexpr dynamic_conf mode(select s)
{
    return dynamic_conf{s};
}

template <select s>
constexpr static_conf<s> mode()
{
    return {};
}

int main()
{
    auto dyna   = mode(select::all);
    auto stati  = mode<select::all>;
}

dyna is a dynamic config, but stati is not a static config, it's a function pointer. To make this work the operator| that is defined for the config elements would have to get an overload that takes functions pointers of functions whose return type is a specialisation of a static conf. It would then forward to the operator| with a default constructed value of that type.

@h-2
Copy link
Member

h-2 commented Jan 2, 2020

BTW: for the problem at hand an enum cannot be used, because strata is a valid mode and that needs an argument . I would propose something like this:

struct search_mode
{
    static constexpr int32_t all = -1;
    static constexpr int32_t all_best = -2;
    static constexpr int32_t best = -3;

    using strata = int32_t;
};

auto m = search_mode::all;
auto m2 = search_mode::strata{2};

int32_t can be replaced with a (non-public) strong type.

@rrahn
Copy link
Contributor Author

rrahn commented Apr 27, 2020

Will be implemented as part of #65

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants