Giriş
Açıklaması şöyle.
Şöyle yaparız.
Elimizde bir variant olsun.
Açıklaması şöyle.
enable/disable the return type (except for class/struct constructors, obviously)Örnek
Şöyle yaparız.
template <typename T>
std::enable_if_t<true == bar<T>()> foo () // version 1
 { }
template <typename T>
std::enable_if_t<false == bar<T>()> foo () // version 2
 { }Elimizde bir variant olsun.
struct EventA {};
struct EventB {};
struct EventC {};
using Event = std::variant<EventA, EventB, EventC>;using State = Visitor::State;
template<class Visitor>
struct VisitorProxy {
    State s;
    template<class E>
    auto operator()(E const& e) -> decltype(Visitor::apply(s, e)) {
        return Visitor::apply(s, e);
    }
    template<class E>
    State operator()(E const&) const {
        return s;
    }
};template <typename Visitor> struct Applicator {
  static State apply(State s, Event e) {
    VisitorProxy<Visitor> p{s};
    return std::visit(p, e);
  }
}; 
Hiç yorum yok:
Yorum Gönder