Skip to content

convert

Alexandre Marcireau edited this page May 31, 2018 · 7 revisions

In header "../third_party/tarsier/source/convert.hpp"

tarsier::convert maps a type to another.

namespace tarsier {
    template <typename Event, typename EventToConvertedEvent, typename HandleConvertedEvent>
    class convert {
        public:
        convert(EventToConvertedEvent event_to_converted_event, HandleConvertedEvent handle_converted_event);

        /// operator() handles an event.
        virtual void operator()(Event event);
    };
}
  • Event is the input type.
  • The expression event_to_converted_event(event), where event is an Event object and x and y are floats, must be valid and return a type compatible with handle_converted_event.
  • The expression handle_converted_event(converted_event), where converted_event is returned by event_to_converted_event, must be valid.

Event must be specified when using make_convert:

struct event {};

struct converted_event {};

auto compute_activity = tarsier::make_convert<event>(
    [](event event) -> converted_event {
        return {};
    },
    [](converted_event converted_event) {
        // do something with converted_event
    });
Clone this wiki locally