История изменений
Исправление quasimoto, (текущая версия) :
Это binary static visitor.
Non-nested pattern matching это что-то вроде (C++14)
template <typename R, typename T, typename F>
R match(std::pair<Pair<T>, Pair<T>> const& x, F const& f) {
return f(x.first.l, x.first.r, x.second.l, x.second.r);
}
// ... other match'es
bool operator()(Pair<T> const& x, Pair<T> const& y) const {
return match<bool>(
std::make_pair(x, y),
[=](auto xl, auto xr, auto yl, auto yr) {
// ^ pattern
return boost::apply_visitor(Iso(), xl, yl) && boost::apply_visitor(Iso(), xr, yr);
});
}
А nested pattern matching — уже вряд ли (ниже есть в «Похожих темах»).
Хотя можно любую вложенную структуру таким match разобрать и закинуть все связи в лямбду (там и переменные можно пропускать), но неудобно и бойлерплейт в виде написания этих match.
Исправление quasimoto, :
Это binary static visitor.
Non-nested pattern matching это что-то вроде (C++14)
template <typename R, typename T, typename F>
R match(std::pair<Pair<T>, Pair<T>> const& x, F const& f) {
return f(x.first.l, x.first.r, x.second.l, x.second.r);
}
// ... other match'es
bool operator()(Pair<T> const& x, Pair<T> const& y) const {
return match<bool>(
std::make_pair(x, y),
[=](auto xl, auto xr, auto yl, auto yr) {
// ^ pattern
return boost::apply_visitor(Iso(), xl, yl) && boost::apply_visitor(Iso(), xr, yr);
});
}
А nested pattern matching — уже вряд ли (ниже есть в «Похожих темах»).
Хотя можно любую вложенную структуру таким match разобрать и закинуть все связи в лямбду (там и переменные можно пропускать), но неудобно и бойлерпейт в виде написания этих match.
Исправление quasimoto, :
Это binary static visitor.
Non-nested pattern matching это что-то вроде (C++14)
template <typename R, typename T, typename F>
R match(std::pair<Pair<T>, Pair<T>> const& x, F const& f) {
return f(x.first.l, x.first.r, x.second.l, x.second.r);
}
// ... other match'es
bool operator()(Pair<T> const& x, Pair<T> const& y) const {
return match<bool>(
std::make_pair(x, y),
[=](auto xl, auto xr, auto yl, auto yr) {
// ^ pattern
return boost::apply_visitor(Iso(), xl, yl) && boost::apply_visitor(Iso(), xr, yr);
});
}
А nested pattern matching — уже вряд ли (ниже есть в «Похожих темах»).
Хотя можно любую вложенную структуру таким match разобрать и закинуть все связи в лямбду (там и переменные можно пропускать), но неудобно и бойлерпейт в виде написания этих match.ф
Исправление quasimoto, :
Это binary static visitor.
Non-nested pattern matching это что-то вроде (C++14)
template <typename R, typename T, typename F>
R match(std::pair<Pair<T>, Pair<T>> const& x, F const& f) {
return f(x.first.l, x.first.r, x.second.l, x.second.r);
}
// ... other match'es
bool operator()(Pair<T> const& x, Pair<T> const& y) const {
return match<bool>(
std::make_pair(x, y),
[=](auto xl, auto xr, auto yl, auto yr) {
// ^ pattern
return boost::apply_visitor(Iso(), xl, yl) && boost::apply_visitor(Iso(), xr, yr);
});
}
А nested pattern matching — уже вряд ли (ниже есть в «Похожих темах»).
Исходная версия quasimoto, :
Это binary static visitor.
Non-nested pattern matching это что-то вроде (C++14)
template <typename R, typename T, typename F>
R match(std::pair<Pair<T>, Pair<T>> const& x, F const& f) {
return f(x.first.l, x.first.r, x.second.l, x.second.r);
}
... other match'es
bool operator()(Pair<T> const& x, Pair<T> const& y) const {
return match<bool>(
std::make_pair(x, y),
[=](auto xl, auto xr, auto yl, auto yr) {
// ^ pattern
return boost::apply_visitor(Iso(), xl, yl) && boost::apply_visitor(Iso(), xr, yr);
});
}
А nested pattern matching — уже вряд ли (ниже есть в «Похожих темах»).