You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
519B

  1. #pragma once
  2. #include <utility>
  3. #include "util/range.h"
  4. namespace DHE {
  5. template <typename T> class Selector {
  6. public:
  7. Selector(std::vector<T> choices, std::function<void(T)> on_selection)
  8. : choices{std::move(choices)}, notify{std::move(on_selection)} {}
  9. /**
  10. * Send notice that the choice at the given position has been selected.
  11. */
  12. void operator()(int position) { notify(choices[position]); }
  13. private:
  14. const std::vector<T> choices;
  15. const std::function<void(T)> notify;
  16. };
  17. } // namespace DHE