From 7dda2d210e47eb482643af4d100297f96ad9265f Mon Sep 17 00:00:00 2001 From: taehyounpark Date: Thu, 11 Apr 2024 00:47:40 -0400 Subject: [PATCH] refactor T::varied -> varied --- include/queryosity/column_series.h | 8 +- include/queryosity/dataflow.h | 34 ++- include/queryosity/dataset_loaded.h | 2 +- include/queryosity/detail.h | 45 ++- include/queryosity/lazy.h | 20 +- include/queryosity/lazy_varied.h | 117 ++++---- include/queryosity/systematic_vary.h | 2 +- include/queryosity/todo.h | 82 +++--- include/queryosity/todo_varied.h | 101 +++---- queryosity.h | 409 ++++++++++++++------------- 10 files changed, 415 insertions(+), 405 deletions(-) diff --git a/include/queryosity/column_series.h b/include/queryosity/column_series.h index 29836f5..7d092cb 100644 --- a/include/queryosity/column_series.h +++ b/include/queryosity/column_series.h @@ -29,8 +29,8 @@ template struct series { auto make(lazy &sel) const; - auto make(lazy::varied &sel) const -> - typename lazy>::varied; + auto make(varied> &sel) const -> + varied>>; protected: Col m_column; @@ -57,8 +57,8 @@ auto queryosity::column::series::make(lazy &sel) const { } template -auto queryosity::column::series::make(lazy::varied &sel) - const -> typename lazy>::varied { +auto queryosity::column::series::make(varied> &sel) + const -> varied>> { auto df = sel.nominal().m_df; return df->get(query::output>()) .fill(m_column) diff --git a/include/queryosity/dataflow.h b/include/queryosity/dataflow.h index f44cc40..bfeb9c6 100644 --- a/include/queryosity/dataflow.h +++ b/include/queryosity/dataflow.h @@ -23,6 +23,8 @@ template class lazy; template class todo; +template class varied; + /** * @ingroup api * @brief Main dataflow interface. @@ -33,6 +35,7 @@ class dataflow { template friend class dataset::loaded; template friend class lazy; template friend class todo; + template friend class varied; public: class node; @@ -157,7 +160,7 @@ class dataflow { * @param[in] column Input column used as cut decision. * @return Lazy varied selection. */ - template auto filter(Col const &col); + template auto filter(varied const &col); /** * @brief Initiate a cutflow. @@ -165,7 +168,7 @@ class dataflow { * @param[in] column Input column used as weight decision. * @return Lazy varied selection. */ - template auto weight(Col const &col); + template auto weight(varied const &col); /** * @brief Initiate a cutflow. @@ -236,19 +239,19 @@ class dataflow { template auto vary(column::constant const &cnst, std::map vars) - -> typename lazy>::varied; + -> varied>>; template auto vary(column::expression const &expr, std::map::function_type> const &vars) -> - typename todo>>::varied; + varied>>>; template auto vary(column::definition const &defn, std::map> const &vars) -> - typename todo>::varied; + varied>>; /* "public" API for Python layer */ @@ -344,6 +347,7 @@ class dataflow::node { public: friend class dataflow; + template friend class varied; public: template @@ -484,8 +488,8 @@ auto queryosity::dataflow::weight(lazy const &col) return this->_apply(col); } -template auto queryosity::dataflow::filter(Col const &col) { - using varied_type = typename lazy::varied; +template auto queryosity::dataflow::filter(varied const &col) { + using varied_type = varied>; varied_type syst(this->filter(col.nominal())); for (auto const &var_name : col.get_variation_names()) { syst.set_variation(var_name, this->filter(col.variation(var_name))); @@ -493,8 +497,8 @@ template auto queryosity::dataflow::filter(Col const &col) { return syst; } -template auto queryosity::dataflow::weight(Col const &col) { - using varied_type = typename lazy::varied; +template auto queryosity::dataflow::weight(varied const &col) { + using varied_type = varied>; varied_type syst(this->weight(col.nominal())); for (auto const &var_name : col.get_variation_names()) { syst.set_variation(var_name, this->weight(col.variation(var_name))); @@ -612,9 +616,9 @@ inline void queryosity::dataflow::reset() { m_analyzed = false; } template auto queryosity::dataflow::vary(column::constant const &cnst, std::map vars) -> - typename lazy>::varied { + varied>> { auto nom = this->define(cnst); - using varied_type = typename lazy>::varied; + using varied_type = varied>>; varied_type syst(std::move(nom)); for (auto const &var : vars) { this->_vary(syst, var.first, column::constant(var.second)); @@ -627,9 +631,9 @@ auto queryosity::dataflow::vary( column::expression const &expr, std::map::function_type> const &vars) -> - typename todo>>::varied { + varied>>> { auto nom = this->_equate(expr); - using varied_type = typename decltype(nom)::varied; + using varied_type = varied; using function_type = typename column::expression::function_type; varied_type syst(std::move(nom)); for (auto const &var : vars) { @@ -642,9 +646,9 @@ template auto queryosity::dataflow::vary( column::definition const &defn, std::map> const &vars) -> - typename todo>::varied { + varied>> { auto nom = this->_define(defn); - using varied_type = typename decltype(nom)::varied; + using varied_type = varied; varied_type syst(std::move(nom)); for (auto const &var : vars) { this->_vary(syst, var.first, var.second); diff --git a/include/queryosity/dataset_loaded.h b/include/queryosity/dataset_loaded.h index 769d75f..2f0fbfb 100644 --- a/include/queryosity/dataset_loaded.h +++ b/include/queryosity/dataset_loaded.h @@ -67,7 +67,7 @@ auto queryosity::dataset::loaded::vary( dataset::column const &col, std::map const &vars) { auto nom = this->read(col); - typename decltype(nom)::varied varied_column(std::move(nom)); + varied varied_column(std::move(nom)); for (auto const &var : vars) { varied_column.set_variation(var.first, this->read(dataset::column(var.second))); diff --git a/include/queryosity/detail.h b/include/queryosity/detail.h index 8be9a91..9773bbe 100644 --- a/include/queryosity/detail.h +++ b/include/queryosity/detail.h @@ -119,9 +119,9 @@ std::enable_if_t && \ queryosity::is_column_v, \ bool> = false> \ - auto operator op_symbol(Arg const &b) const -> typename lazy< \ - typename decltype(std::declval>().operator op_symbol( \ - b.nominal()))::action_type>::varied; + auto operator op_symbol(Arg const &b) const -> varied< \ + lazy>(). \ + operator op_symbol(b.nominal()))::action_type>>; #define DEFINE_LAZY_VARIED_BINARY_OP(op_symbol) \ template \ @@ -130,15 +130,15 @@ std::enable_if_t && \ queryosity::is_column_v, \ bool>> \ - auto queryosity::lazy::varied::operator op_symbol(Arg const &b) const \ - -> typename lazy< \ - typename decltype(std::declval>().operator op_symbol( \ - b.nominal()))::action_type>::varied { \ - auto syst = typename lazy< \ - typename decltype(std::declval>().operator op_symbol( \ - b.nominal()))::action_type>::varied(this->nominal(). \ - operator op_symbol( \ - b.nominal())); \ + auto queryosity::varied>::operator op_symbol( \ + Arg const &b) const \ + -> varied< \ + lazy>().operator op_symbol( \ + b.nominal()))::action_type>> { \ + auto syst = varied< \ + lazy>().operator op_symbol( \ + b.nominal()))::action_type>>( \ + this->nominal().operator op_symbol(b.nominal())); \ for (auto const &var_name : systematic::get_variation_names(*this, b)) { \ syst.set_variation(var_name, variation(var_name).operator op_symbol( \ b.variation(var_name))); \ @@ -149,20 +149,19 @@ #define DECLARE_LAZY_VARIED_UNARY_OP(op_symbol) \ template , bool> = false> \ - auto operator op_symbol() const -> typename lazy< \ - typename decltype(std::declval>(). \ - operator op_symbol())::action_type>::varied; + auto operator op_symbol() const -> varied< \ + queryosity::lazy>(). \ + operator op_symbol())::action_type>>; #define DEFINE_LAZY_VARIED_UNARY_OP(op_name, op_symbol) \ template \ template , bool>> \ - auto queryosity::lazy::varied::operator op_symbol() const -> \ - typename lazy< \ - typename decltype(std::declval>(). \ - operator op_symbol())::action_type>::varied { \ - auto syst = \ - typename lazy>(). \ - operator op_symbol())::action_type>:: \ - varied(this->nominal().operator op_symbol()); \ + auto queryosity::varied>::operator op_symbol() const \ + -> varied>(). \ + operator op_symbol())::action_type>> { \ + auto syst = varied>(). \ + operator op_symbol())::action_type>>( \ + this->nominal().operator op_symbol()); \ for (auto const &var_name : systematic::get_variation_names(*this)) { \ syst.set_variation(var_name, variation(var_name).operator op_symbol()); \ } \ diff --git a/include/queryosity/lazy.h b/include/queryosity/lazy.h index 8a37b90..cebe0de 100644 --- a/include/queryosity/lazy.h +++ b/include/queryosity/lazy.h @@ -24,9 +24,6 @@ class lazy : public dataflow::node, public systematic::resolver>, public query::result_of { -public: - class varied; - public: using action_type = Action; @@ -56,12 +53,14 @@ class lazy : public dataflow::node, virtual std::vector const &get_slots() const final override; - virtual void set_variation(const std::string &var_name, lazy var) final override; + virtual void set_variation(const std::string &var_name, + lazy var) final override; virtual lazy &nominal() final override; virtual lazy &variation(const std::string &var_name) final override; virtual lazy const &nominal() const final override; - virtual lazy const &variation(const std::string &var_name) const final override; + virtual lazy const & + variation(const std::string &var_name) const final override; virtual bool has_variation(const std::string &var_name) const final override; virtual std::set get_variation_names() const final override; @@ -163,8 +162,8 @@ class lazy : public dataflow::node, */ template , bool> = false> - auto get(column::series const &col) -> typename lazy< - query::series::value_type>>::varied; + auto get(column::series const &col) + -> varied::value_type>>>; /** * @brief (Process and) retrieve the result of a query. @@ -338,7 +337,7 @@ template template auto queryosity::lazy::filter(Col const &col) const { if constexpr (std::is_base_of_v) { - using varied_type = typename lazy::varied; + using varied_type = varied>; auto syst = varied_type(this->filter(col.nominal())); for (auto const &var_name : col.get_variation_names()) { syst.set_variation(var_name, this->filter(col.variation(var_name))); @@ -354,7 +353,7 @@ template template auto queryosity::lazy::weight(Col const &col) const { if constexpr (std::is_base_of_v) { - using varied_type = typename lazy::varied; + using varied_type = varied>; auto syst = varied_type(this->weight(col.nominal())); for (auto const &var_name : col.get_variation_names()) { syst.set_variation(var_name, this->weight(col.variation(var_name))); @@ -416,8 +415,7 @@ auto queryosity::lazy::get(queryosity::column::series const &col) template template , bool>> auto queryosity::lazy::get(queryosity::column::series const &col) - -> typename lazy< - query::series::value_type>>::varied { + -> varied::value_type>>> { return col.make(*this); } diff --git a/include/queryosity/lazy_varied.h b/include/queryosity/lazy_varied.h index 5bbb79a..0fe51d9 100644 --- a/include/queryosity/lazy_varied.h +++ b/include/queryosity/lazy_varied.h @@ -11,6 +11,8 @@ namespace queryosity { +template class varied; + /** * @ingroup api * @brief Variations of a lazy action. @@ -21,7 +23,7 @@ namespace queryosity { * behaves functionally identical to a nominal-only one. */ template -class lazy::varied : public dataflow::node, +class varied> : public dataflow::node, public systematic::resolver> { public: @@ -37,16 +39,17 @@ class lazy::varied : public dataflow::node, varied(varied &&) = default; varied &operator=(varied &&) = default; - template varied(typename lazy::varied const &); - template - varied &operator=(typename lazy::varied const &); + template varied(varied> const &); + template varied &operator=(varied> const &); - virtual void set_variation(const std::string &var_name, lazy var) final override; + virtual void set_variation(const std::string &var_name, + lazy var) final override; - virtual lazy &nominal() final override; - virtual lazy &variation(const std::string &var_name) final override; - virtual lazy const &nominal() const final override; - virtual lazy const &variation(const std::string &var_name) const final override; + virtual lazy &nominal() final override; + virtual lazy &variation(const std::string &var_name) final override; + virtual lazy const &nominal() const final override; + virtual lazy const & + variation(const std::string &var_name) const final override; virtual bool has_variation(const std::string &var_name) const final override; virtual std::set get_variation_names() const final override; @@ -59,7 +62,7 @@ class lazy::varied : public dataflow::node, */ template , bool> = false> - auto filter(Col const &col) -> typename lazy::varied; + auto filter(Col const &col) -> varied>; /** * @brief Compound a weight to this selection. @@ -69,18 +72,17 @@ class lazy::varied : public dataflow::node, */ template , bool> = false> - auto weight(Col const &col) -> typename lazy::varied; + auto weight(Col const &col) -> varied>; template , bool> = false> - auto filter(column::expression const &expr) -> typename todo< - selection::applicator>>::varied; + auto filter(column::expression const &expr) -> varied< + todo>>>; template , bool> = false> - auto weight(column::expression const &expr) -> - typename todo>>::varied; + auto weight(column::expression const &expr) -> varied< + todo>>>; template , bool> = false> @@ -126,13 +128,13 @@ class lazy::varied : public dataflow::node, #include "selection.h" template -queryosity::lazy::varied::varied(lazy nom) +queryosity::varied>::varied(queryosity::lazy nom) : dataflow::node(*nom.m_df), m_nom(std::move(nom)) {} template template -queryosity::lazy::varied::varied( - typename lazy::varied const &other) { +queryosity::varied>::varied( + varied> const &other) { this->m_df = other.m_df; this->m_var_names = other.m_var_names; for (auto const &var : other.m_var_map) { @@ -142,9 +144,9 @@ queryosity::lazy::varied::varied( template template -typename queryosity::lazy::varied & -queryosity::lazy::varied::operator=( - typename lazy::varied const &other) { +queryosity::varied> & +queryosity::varied>::operator=( + varied> const &other) { this->m_df = other.m_df; this->m_var_names = other.m_var_names; for (auto const &var : other.m_var_map) { @@ -154,8 +156,8 @@ queryosity::lazy::varied::operator=( } template -void queryosity::lazy::varied::set_variation(const std::string &var_name, - lazy var) { +void queryosity::varied>::set_variation( + const std::string &var_name, queryosity::lazy var) { ensemble::invoke( [var_name](action *act) { act->set_variation_name(var_name); }, var.get_slots()); @@ -164,46 +166,48 @@ void queryosity::lazy::varied::set_variation(const std::string &var_name, } template -auto queryosity::lazy::varied::nominal() -> lazy & { +auto queryosity::varied>::nominal() + -> queryosity::lazy & { return this->m_nom; } template -auto queryosity::lazy::varied::variation(const std::string &var_name) - -> lazy & { +auto queryosity::varied>::variation( + const std::string &var_name) -> queryosity::lazy & { return (this->has_variation(var_name) ? m_var_map.at(var_name) : m_nom); } template -auto queryosity::lazy::varied::nominal() const -> lazy const & { +auto queryosity::varied>::nominal() const + -> queryosity::lazy const & { return this->m_nom; } template -auto queryosity::lazy::varied::variation(const std::string &var_name) const - -> lazy const & { +auto queryosity::varied>::variation( + const std::string &var_name) const -> queryosity::lazy const & { return (this->has_variation(var_name) ? m_var_map.at(var_name) : m_nom); } template -bool queryosity::lazy::varied::has_variation( +bool queryosity::varied>::has_variation( const std::string &var_name) const { return m_var_map.find(var_name) != m_var_map.end(); } template std::set -queryosity::lazy::varied::get_variation_names() const { +queryosity::varied>::get_variation_names() const { return m_var_names; } template template , bool>> -auto queryosity::lazy::varied::filter(Col const &col) -> - typename lazy::varied { +auto queryosity::varied>::filter(Col const &col) + -> varied> { - using varied_type = typename lazy::varied; + using varied_type = varied>; auto syst = varied_type(this->nominal().filter(col.nominal())); @@ -217,10 +221,10 @@ auto queryosity::lazy::varied::filter(Col const &col) -> template template , bool>> -auto queryosity::lazy::varied::weight(Col const &col) -> - typename lazy::varied { +auto queryosity::varied>::weight(Col const &col) + -> varied> { - using varied_type = typename lazy::varied; + using varied_type = varied>; auto syst = varied_type(this->nominal().weight(col.nominal())); @@ -234,13 +238,13 @@ auto queryosity::lazy::varied::weight(Col const &col) -> template template , bool>> -auto queryosity::lazy::varied::filter( - queryosity::column::expression const &expr) -> - typename todo>>::varied { +auto queryosity::varied>::filter( + queryosity::column::expression const &expr) + -> varied< + todo>>> { - using varied_type = typename todo< - selection::applicator>>::varied; + using varied_type = varied< + todo>>>; auto syst = varied_type(this->nominal().filter(expr)); @@ -253,14 +257,13 @@ auto queryosity::lazy::varied::filter( template template , bool>> -auto queryosity::lazy::varied::weight( - queryosity::column::expression const &expr) -> - typename todo>>::varied { +auto queryosity::varied>::weight( + queryosity::column::expression const &expr) + -> varied>>> { - using varied_type = - typename todo>>::varied; + using varied_type = varied< + todo>>>; auto syst = varied_type(this->nominal().weight(expr)); @@ -273,22 +276,22 @@ auto queryosity::lazy::varied::weight( template template , bool>> -auto queryosity::lazy::varied::book(Agg &&agg) { +auto queryosity::varied>::book(Agg &&agg) { return agg.at(*this); } template template , bool>> -auto queryosity::lazy::varied::book(Aggs &&...aggs) { +auto queryosity::varied>::book(Aggs &&...aggs) { return std::make_tuple((aggs.at(*this), ...)); } template template , bool>> -auto queryosity::lazy::varied::operator[](const std::string &var_name) - -> lazy & { +auto queryosity::varied>::operator[]( + const std::string &var_name) -> queryosity::lazy & { if (!this->has_variation(var_name)) { throw std::out_of_range("variation does not exist"); } @@ -298,8 +301,8 @@ auto queryosity::lazy::varied::operator[](const std::string &var_name) template template , bool>> -auto queryosity::lazy::varied::operator[]( - const std::string &var_name) const -> lazy const & { +auto queryosity::varied>::operator[]( + const std::string &var_name) const -> queryosity::lazy const & { if (!this->has_variation(var_name)) { throw std::out_of_range("variation does not exist"); } diff --git a/include/queryosity/systematic_vary.h b/include/queryosity/systematic_vary.h index fed0888..b771f8a 100644 --- a/include/queryosity/systematic_vary.h +++ b/include/queryosity/systematic_vary.h @@ -26,7 +26,7 @@ auto queryosity::systematic::vary(systematic::nominal const &nom, using action_type = typename Lzy::action_type; using value_type = column::value_t; using nominal_type = lazy>; - using varied_type = typename nominal_type::varied; + using varied_type = varied; varied_type syst(nom.get().template to()); (syst.set_variation(vars.name(), vars.get().template to()), ...); return syst; diff --git a/include/queryosity/todo.h b/include/queryosity/todo.h index 77e80ad..9db0de8 100644 --- a/include/queryosity/todo.h +++ b/include/queryosity/todo.h @@ -1,9 +1,9 @@ #pragma once #include "dataflow.h" +#include "detail.h" #include "lazy.h" #include "lazy_varied.h" -#include "detail.h" #include "systematic.h" #include "systematic_resolver.h" @@ -22,9 +22,6 @@ class todo : public dataflow::node, public ensemble::slotted, public systematic::resolver> { -public: - class varied; - public: todo(dataflow &df, std::vector> bkr); virtual ~todo() = default; @@ -34,12 +31,14 @@ class todo : public dataflow::node, virtual std::vector const &get_slots() const final override; - virtual void set_variation(const std::string &var_name, todo var) final override; + virtual void set_variation(const std::string &var_name, + todo var) final override; virtual todo &nominal() final override; virtual todo &variation(const std::string &var_name) final override; virtual todo const &nominal() const final override; - virtual todo const &variation(const std::string &var_name) const final override; + virtual todo const & + variation(const std::string &var_name) const final override; virtual bool has_variation(const std::string &var_name) const final override; virtual std::set get_variation_names() const final override; @@ -49,9 +48,9 @@ class todo : public dataflow::node, * @param[in] columns Input columns. * @param[in][out] Evaluated column. */ - template , - bool> = false> + template < + typename... Nodes, typename V = Helper, + std::enable_if_t, bool> = false> auto evaluate(Nodes &&...columns) const -> decltype(std::declval>()._evaluate( std::forward(columns)...)) { @@ -63,9 +62,9 @@ class todo : public dataflow::node, * @param[in] columns Input columns. * @param[in][out] Applied selection. */ - template , - bool> = false> + template < + typename... Nodes, typename V = Helper, + std::enable_if_t, bool> = false> auto apply(Nodes &&...columns) const -> decltype(std::declval>()._apply( std::forward(columns)...)) { @@ -78,8 +77,7 @@ class todo : public dataflow::node, * @returns Updated query plan filled with input columns. */ template , - bool> = false> + std::enable_if_t, bool> = false> auto fill(Nodes &&...columns) const -> decltype(std::declval>()._fill(std::declval()...)) { return this->_fill(std::forward(columns)...); @@ -111,13 +109,12 @@ class todo : public dataflow::node, * @param[in] columns... Input columns. * @return Evaluated column. */ - template - auto operator()(Args &&...columns) const { - if constexpr( column::is_evaluatable_v ) { + template auto operator()(Args &&...columns) const { + if constexpr (column::is_evaluatable_v) { return this->evaluate(std::forward(columns)...); - } else if constexpr( selection::is_applicable_v ) { + } else if constexpr (selection::is_applicable_v) { return this->apply(std::forward(columns)...); - } else if constexpr( query::is_fillable_v ) { + } else if constexpr (query::is_fillable_v) { return this->fill(std::forward(columns)...); } } @@ -136,10 +133,11 @@ class todo : public dataflow::node, std::enable_if_t && queryosity::has_variation_v, bool> = false> - auto _evaluate(Nodes const &...columns) const -> - typename lazy>>>::varied { + auto _evaluate(Nodes const &...columns) const + -> varied>>>> { - using varied_type = typename lazy>>>::varied; + using varied_type = + varied>>>>; auto nom = this->m_df->_evaluate(*this, columns.nominal()...); auto syst = varied_type(std::move(nom)); @@ -156,27 +154,27 @@ class todo : public dataflow::node, std::enable_if_t && queryosity::has_no_variation_v, bool> = false> - auto _apply(Nodes const &...columns) const - -> lazy { + auto _apply(Nodes const &...columns) const -> lazy { using selection_type = typename V::selection_type; - return this->m_df->template _apply(*this,columns...); + return this->m_df->template _apply(*this, columns...); } template && queryosity::has_variation_v, bool> = false> - auto _apply(Nodes const &...columns) const -> - typename lazy::varied { + auto _apply(Nodes const &...columns) const -> varied> { using selection_type = typename V::selection_type; - using varied_type = typename lazy>::varied; + using varied_type = varied>>; - auto nom = this->m_df->template _apply(*this,columns.nominal()...); + auto nom = this->m_df->template _apply( + *this, columns.nominal()...); auto syst = varied_type(std::move(nom)); for (auto const &var_name : systematic::get_variation_names(columns...)) { - auto var = this->m_df->template _apply(*this,columns.variation(var_name)...); + auto var = this->m_df->template _apply( + *this, columns.variation(var_name)...); syst.set_variation(var_name, std::move(var)); } @@ -195,9 +193,8 @@ class todo : public dataflow::node, std::enable_if_t && queryosity::is_varied_v, bool> = false> - auto _book(Node const &sel) const -> - typename lazy>::varied { - using varied_type = typename lazy>::varied; + auto _book(Node const &sel) const -> varied>> { + using varied_type = varied>>; auto syst = varied_type(this->m_df->_book(*this, sel.nominal())); for (auto const &var_name : systematic::get_variation_names(sel)) { syst.set_variation(var_name, @@ -221,11 +218,9 @@ class todo : public dataflow::node, has_variation_v, bool> = false> auto _book(Nodes const &...sels) const - -> std::array>::varied, - sizeof...(Nodes)> { - using varied_type = typename lazy>::varied; - using array_of_varied_type = - std::array>::varied, sizeof...(Nodes)>; + -> std::array>>, sizeof...(Nodes)> { + using varied_type = varied>>; + using array_of_varied_type = std::array; auto var_names = systematic::get_variation_names(sels...); auto _book_varied = [var_names, @@ -257,8 +252,9 @@ class todo : public dataflow::node, std::enable_if_t && has_variation_v, bool> = false> - auto _fill(Nodes const &...columns) const -> varied { - auto syst = varied(std::move(this->_fill(columns.nominal()...))); + auto _fill(Nodes const &...columns) const -> varied> { + using varied_type = varied>; + auto syst = varied_type(std::move(this->_fill(columns.nominal()...))); for (auto const &var_name : systematic::get_variation_names(columns...)) { syst.set_variation( var_name, std::move(this->_fill(columns.variation(var_name)...))); @@ -295,13 +291,15 @@ void queryosity::todo::set_variation(const std::string &, throw std::logic_error("cannot set variation to a nominal-only action"); } -template auto queryosity::todo::nominal() -> todo & { +template +auto queryosity::todo::nominal() -> todo & { // this is nominal return *this; } template -auto queryosity::todo::variation(const std::string &) -> todo & { +auto queryosity::todo::variation(const std::string &) + -> todo & { // propagation of variations must occur "transparently" return *this; } diff --git a/include/queryosity/todo_varied.h b/include/queryosity/todo_varied.h index 91330f2..8c7ffc9 100644 --- a/include/queryosity/todo_varied.h +++ b/include/queryosity/todo_varied.h @@ -12,7 +12,7 @@ namespace queryosity { * corresponding to nominal and systematic variations. */ template -class todo::varied : public dataflow::node, +class varied> : public dataflow::node, systematic::resolver> { public: @@ -22,12 +22,14 @@ class todo::varied : public dataflow::node, varied(varied &&) = default; varied &operator=(varied &&) = default; - virtual void set_variation(const std::string &var_name, todo var) final override; + virtual void set_variation(const std::string &var_name, + todo var) final override; - virtual todo &nominal() final override; - virtual todo &variation(const std::string &var_name) final override; - virtual todo const &nominal() const final override; - virtual todo const &variation(const std::string &var_name) const final override; + virtual todo &nominal() final override; + virtual todo &variation(const std::string &var_name) final override; + virtual todo const &nominal() const final override; + virtual todo const & + variation(const std::string &var_name) const final override; virtual bool has_variation(const std::string &var_name) const final override; virtual std::set get_variation_names() const final override; @@ -36,14 +38,13 @@ class todo::varied : public dataflow::node, template < typename... Cols, typename V = Helper, std::enable_if_t, bool> = false> - auto evaluate(Cols &&...cols) -> typename decltype(this->nominal().evaluate( - std::forward(cols.nominal)...))::varied; + auto evaluate(Cols &&...cols) -> varied< + decltype(this->nominal().evaluate(std::forward(cols.nominal)...))>; template < typename... Cols, typename V = Helper, std::enable_if_t, bool> = false> - auto apply(Cols &&...cols) -> - typename queryosity::lazy>::varied; + auto apply(Cols &&...cols) -> varied>>; /** * @brief Fill the query with input columns. @@ -61,7 +62,7 @@ class todo::varied : public dataflow::node, */ template , bool> = false> - auto at(Node const &selection) -> typename lazy>::varied; + auto at(Node const &selection) -> varied>>; /** * @brief Book the query at multiple selections. @@ -71,13 +72,12 @@ class todo::varied : public dataflow::node, template , bool> = false> auto at(Nodes const &...selections) - -> std::array>::varied, - sizeof...(Nodes)>; + -> std::array>>, sizeof...(Nodes)>; template - auto operator()(Cols &&...cols) -> - typename decltype(std::declval>().operator()( - std::forward(cols).nominal()...))::varied; + auto operator()(Cols &&...cols) + -> varied>().operator()( + std::forward(cols).nominal()...))>; protected: todo m_nominal; @@ -92,60 +92,62 @@ class todo::varied : public dataflow::node, #include "selection.h" template -queryosity::todo::varied::varied(todo &&nom) +queryosity::varied>::varied( + queryosity::todo &&nom) : dataflow::node(*nom.m_df), m_nominal(std::move(nom)) {} template -void queryosity::todo::varied::set_variation( - const std::string &var_name, todo var) { +void queryosity::varied>::set_variation( + const std::string &var_name, queryosity::todo var) { m_variation_map.insert(std::move(std::make_pair(var_name, std::move(var)))); m_variation_names.insert(var_name); } template -auto queryosity::todo::varied::nominal() -> todo & { +auto queryosity::varied>::nominal() -> todo & { return m_nominal; } template -auto queryosity::todo::varied::nominal() const -> todo const & { +auto queryosity::varied>::nominal() const + -> todo const & { return m_nominal; } template -auto queryosity::todo::varied::variation(const std::string &var_name) - -> todo & { +auto queryosity::varied>::variation( + const std::string &var_name) -> todo & { return (this->has_variation(var_name) ? m_variation_map.at(var_name) : m_nominal); } template -auto queryosity::todo::varied::variation( - const std::string &var_name) const -> todo const & { +auto queryosity::varied>::variation( + const std::string &var_name) const -> todo const & { return (this->has_variation(var_name) ? m_variation_map.at(var_name) : m_nominal); } template -bool queryosity::todo::varied::has_variation( +bool queryosity::varied>::has_variation( const std::string &var_name) const { return m_variation_map.find(var_name) != m_variation_map.end(); } template std::set -queryosity::todo::varied::get_variation_names() const { +queryosity::varied>::get_variation_names() const { return m_variation_names; } template template , bool>> -auto queryosity::todo::varied::evaluate(Cols &&...cols) -> - typename decltype(this->nominal().evaluate( - std::forward(cols.nominal)...))::varied { - using varied_type = typename decltype(this->nominal().evaluate( - std::forward(cols.nominal)...))::varied; +auto queryosity::varied>::evaluate(Cols &&...cols) + -> variednominal().evaluate( + std::forward(cols.nominal)...))> { + using varied_type = variednominal().evaluate( + std::forward(cols.nominal)...))>; auto syst = varied_type( this->nominal().evaluate(std::forward(cols).nominal()...)); for (auto const &var_name : @@ -160,10 +162,9 @@ auto queryosity::todo::varied::evaluate(Cols &&...cols) -> template template , bool>> -auto queryosity::todo::varied::apply(Cols &&...cols) -> - typename queryosity::lazy>::varied { - using varied_type = - typename queryosity::lazy>::varied; +auto queryosity::varied>::apply(Cols &&...cols) + -> varied>> { + using varied_type = varied>>; auto syst = varied_type(this->nominal().apply(std::forward(cols).nominal()...)); for (auto const &var_name : @@ -178,7 +179,8 @@ auto queryosity::todo::varied::apply(Cols &&...cols) -> template template , bool>> -auto queryosity::todo::varied::fill(Nodes const &...columns) -> varied { +auto queryosity::varied>::fill(Nodes const &...columns) + -> varied { auto syst = varied(std::move(this->nominal().fill(columns.nominal()...))); for (auto const &var_name : systematic::get_variation_names(*this, columns...)) { @@ -191,9 +193,9 @@ auto queryosity::todo::varied::fill(Nodes const &...columns) -> varied { template template , bool>> -auto queryosity::todo::varied::at(Node const &selection) -> - typename lazy>::varied { - using varied_type = typename lazy>::varied; +auto queryosity::varied>::at(Node const &selection) + -> varied>> { + using varied_type = varied>>; auto syst = varied_type(this->nominal().at(selection.nominal())); for (auto const &var_name : systematic::get_variation_names(*this, selection)) { @@ -206,12 +208,13 @@ auto queryosity::todo::varied::at(Node const &selection) -> template template , bool>> -auto queryosity::todo::varied::at(Nodes const &...selections) - -> std::array>::varied, sizeof...(Nodes)> { +auto queryosity::varied>::at( + Nodes const &...selections) + -> std::array>>, sizeof...(Nodes)> { // variations - using varied_type = typename lazy>::varied; + using varied_type = varied>>; using array_of_varied_type = - std::array>::varied, sizeof...(Nodes)>; + std::array>>, sizeof...(Nodes)>; auto var_names = systematic::get_variation_names(*this, selections...); auto _book_varied = [var_names, @@ -228,12 +231,12 @@ auto queryosity::todo::varied::at(Nodes const &...selections) template template -auto queryosity::todo::varied::operator()(Cols &&...cols) -> - typename decltype(std::declval>().operator()( - std::forward(cols).nominal()...))::varied { +auto queryosity::varied>::operator()(Cols &&...cols) + -> varied>().operator()( + std::forward(cols).nominal()...))> { - using varied_type = typename decltype(std::declval>().operator()( - std::forward(cols).nominal()...))::varied; + using varied_type = varied>().operator()( + std::forward(cols).nominal()...))>; auto syst = varied_type( this->nominal().operator()(std::forward(cols).nominal()...)); diff --git a/queryosity.h b/queryosity.h index 99fc67c..c017732 100644 --- a/queryosity.h +++ b/queryosity.h @@ -2094,6 +2094,8 @@ template class lazy; template class todo; +template class varied; + /** * @ingroup api * @brief Main dataflow interface. @@ -2104,6 +2106,7 @@ class dataflow { template friend class dataset::loaded; template friend class lazy; template friend class todo; + template friend class varied; public: class node; @@ -2228,7 +2231,7 @@ class dataflow { * @param[in] column Input column used as cut decision. * @return Lazy varied selection. */ - template auto filter(Col const &col); + template auto filter(varied const &col); /** * @brief Initiate a cutflow. @@ -2236,7 +2239,7 @@ class dataflow { * @param[in] column Input column used as weight decision. * @return Lazy varied selection. */ - template auto weight(Col const &col); + template auto weight(varied const &col); /** * @brief Initiate a cutflow. @@ -2307,19 +2310,19 @@ class dataflow { template auto vary(column::constant const &cnst, std::map vars) - -> typename lazy>::varied; + -> varied>>; template auto vary(column::expression const &expr, std::map::function_type> const &vars) -> - typename todo>>::varied; + varied>>>; template auto vary(column::definition const &defn, std::map> const &vars) -> - typename todo>::varied; + varied>>; /* "public" API for Python layer */ @@ -2415,6 +2418,7 @@ class dataflow::node { public: friend class dataflow; + template friend class varied; public: template @@ -2674,9 +2678,9 @@ auto queryosity::dataset::column::_read( std::enable_if_t && \ queryosity::is_column_v, \ bool> = false> \ - auto operator op_symbol(Arg const &b) const -> typename lazy< \ - typename decltype(std::declval>().operator op_symbol( \ - b.nominal()))::action_type>::varied; + auto operator op_symbol(Arg const &b) const -> varied< \ + lazy>(). \ + operator op_symbol(b.nominal()))::action_type>>; #define DEFINE_LAZY_VARIED_BINARY_OP(op_symbol) \ template \ @@ -2685,15 +2689,15 @@ auto queryosity::dataset::column::_read( std::enable_if_t && \ queryosity::is_column_v, \ bool>> \ - auto queryosity::lazy::varied::operator op_symbol(Arg const &b) const \ - -> typename lazy< \ - typename decltype(std::declval>().operator op_symbol( \ - b.nominal()))::action_type>::varied { \ - auto syst = typename lazy< \ - typename decltype(std::declval>().operator op_symbol( \ - b.nominal()))::action_type>::varied(this->nominal(). \ - operator op_symbol( \ - b.nominal())); \ + auto queryosity::varied>::operator op_symbol( \ + Arg const &b) const \ + -> varied< \ + lazy>().operator op_symbol( \ + b.nominal()))::action_type>> { \ + auto syst = varied< \ + lazy>().operator op_symbol( \ + b.nominal()))::action_type>>( \ + this->nominal().operator op_symbol(b.nominal())); \ for (auto const &var_name : systematic::get_variation_names(*this, b)) { \ syst.set_variation(var_name, variation(var_name).operator op_symbol( \ b.variation(var_name))); \ @@ -2704,20 +2708,19 @@ auto queryosity::dataset::column::_read( #define DECLARE_LAZY_VARIED_UNARY_OP(op_symbol) \ template , bool> = false> \ - auto operator op_symbol() const -> typename lazy< \ - typename decltype(std::declval>(). \ - operator op_symbol())::action_type>::varied; + auto operator op_symbol() const -> varied< \ + queryosity::lazy>(). \ + operator op_symbol())::action_type>>; #define DEFINE_LAZY_VARIED_UNARY_OP(op_name, op_symbol) \ template \ template , bool>> \ - auto queryosity::lazy::varied::operator op_symbol() const -> \ - typename lazy< \ - typename decltype(std::declval>(). \ - operator op_symbol())::action_type>::varied { \ - auto syst = \ - typename lazy>(). \ - operator op_symbol())::action_type>:: \ - varied(this->nominal().operator op_symbol()); \ + auto queryosity::varied>::operator op_symbol() const \ + -> varied>(). \ + operator op_symbol())::action_type>> { \ + auto syst = varied>(). \ + operator op_symbol())::action_type>>( \ + this->nominal().operator op_symbol()); \ for (auto const &var_name : systematic::get_variation_names(*this)) { \ syst.set_variation(var_name, variation(var_name).operator op_symbol()); \ } \ @@ -2826,9 +2829,6 @@ class lazy : public dataflow::node, public systematic::resolver>, public query::result_of { -public: - class varied; - public: using action_type = Action; @@ -2858,12 +2858,14 @@ class lazy : public dataflow::node, virtual std::vector const &get_slots() const final override; - virtual void set_variation(const std::string &var_name, lazy var) final override; + virtual void set_variation(const std::string &var_name, + lazy var) final override; virtual lazy &nominal() final override; virtual lazy &variation(const std::string &var_name) final override; virtual lazy const &nominal() const final override; - virtual lazy const &variation(const std::string &var_name) const final override; + virtual lazy const & + variation(const std::string &var_name) const final override; virtual bool has_variation(const std::string &var_name) const final override; virtual std::set get_variation_names() const final override; @@ -2965,8 +2967,8 @@ class lazy : public dataflow::node, */ template , bool> = false> - auto get(column::series const &col) -> typename lazy< - query::series::value_type>>::varied; + auto get(column::series const &col) + -> varied::value_type>>>; /** * @brief (Process and) retrieve the result of a query. @@ -3025,6 +3027,8 @@ class lazy : public dataflow::node, namespace queryosity { +template class varied; + /** * @ingroup api * @brief Variations of a lazy action. @@ -3035,7 +3039,7 @@ namespace queryosity { * behaves functionally identical to a nominal-only one. */ template -class lazy::varied : public dataflow::node, +class varied> : public dataflow::node, public systematic::resolver> { public: @@ -3051,16 +3055,17 @@ class lazy::varied : public dataflow::node, varied(varied &&) = default; varied &operator=(varied &&) = default; - template varied(typename lazy::varied const &); - template - varied &operator=(typename lazy::varied const &); + template varied(varied> const &); + template varied &operator=(varied> const &); - virtual void set_variation(const std::string &var_name, lazy var) final override; + virtual void set_variation(const std::string &var_name, + lazy var) final override; - virtual lazy &nominal() final override; - virtual lazy &variation(const std::string &var_name) final override; - virtual lazy const &nominal() const final override; - virtual lazy const &variation(const std::string &var_name) const final override; + virtual lazy &nominal() final override; + virtual lazy &variation(const std::string &var_name) final override; + virtual lazy const &nominal() const final override; + virtual lazy const & + variation(const std::string &var_name) const final override; virtual bool has_variation(const std::string &var_name) const final override; virtual std::set get_variation_names() const final override; @@ -3073,7 +3078,7 @@ class lazy::varied : public dataflow::node, */ template , bool> = false> - auto filter(Col const &col) -> typename lazy::varied; + auto filter(Col const &col) -> varied>; /** * @brief Compound a weight to this selection. @@ -3083,18 +3088,17 @@ class lazy::varied : public dataflow::node, */ template , bool> = false> - auto weight(Col const &col) -> typename lazy::varied; + auto weight(Col const &col) -> varied>; template , bool> = false> - auto filter(column::expression const &expr) -> typename todo< - selection::applicator>>::varied; + auto filter(column::expression const &expr) -> varied< + todo>>>; template , bool> = false> - auto weight(column::expression const &expr) -> - typename todo>>::varied; + auto weight(column::expression const &expr) -> varied< + todo>>>; template , bool> = false> @@ -3138,13 +3142,13 @@ class lazy::varied : public dataflow::node, } // namespace queryosity template -queryosity::lazy::varied::varied(lazy nom) +queryosity::varied>::varied(queryosity::lazy nom) : dataflow::node(*nom.m_df), m_nom(std::move(nom)) {} template template -queryosity::lazy::varied::varied( - typename lazy::varied const &other) { +queryosity::varied>::varied( + varied> const &other) { this->m_df = other.m_df; this->m_var_names = other.m_var_names; for (auto const &var : other.m_var_map) { @@ -3154,9 +3158,9 @@ queryosity::lazy::varied::varied( template template -typename queryosity::lazy::varied & -queryosity::lazy::varied::operator=( - typename lazy::varied const &other) { +queryosity::varied> & +queryosity::varied>::operator=( + varied> const &other) { this->m_df = other.m_df; this->m_var_names = other.m_var_names; for (auto const &var : other.m_var_map) { @@ -3166,8 +3170,8 @@ queryosity::lazy::varied::operator=( } template -void queryosity::lazy::varied::set_variation(const std::string &var_name, - lazy var) { +void queryosity::varied>::set_variation( + const std::string &var_name, queryosity::lazy var) { ensemble::invoke( [var_name](action *act) { act->set_variation_name(var_name); }, var.get_slots()); @@ -3176,46 +3180,48 @@ void queryosity::lazy::varied::set_variation(const std::string &var_name, } template -auto queryosity::lazy::varied::nominal() -> lazy & { +auto queryosity::varied>::nominal() + -> queryosity::lazy & { return this->m_nom; } template -auto queryosity::lazy::varied::variation(const std::string &var_name) - -> lazy & { +auto queryosity::varied>::variation( + const std::string &var_name) -> queryosity::lazy & { return (this->has_variation(var_name) ? m_var_map.at(var_name) : m_nom); } template -auto queryosity::lazy::varied::nominal() const -> lazy const & { +auto queryosity::varied>::nominal() const + -> queryosity::lazy const & { return this->m_nom; } template -auto queryosity::lazy::varied::variation(const std::string &var_name) const - -> lazy const & { +auto queryosity::varied>::variation( + const std::string &var_name) const -> queryosity::lazy const & { return (this->has_variation(var_name) ? m_var_map.at(var_name) : m_nom); } template -bool queryosity::lazy::varied::has_variation( +bool queryosity::varied>::has_variation( const std::string &var_name) const { return m_var_map.find(var_name) != m_var_map.end(); } template std::set -queryosity::lazy::varied::get_variation_names() const { +queryosity::varied>::get_variation_names() const { return m_var_names; } template template , bool>> -auto queryosity::lazy::varied::filter(Col const &col) -> - typename lazy::varied { +auto queryosity::varied>::filter(Col const &col) + -> varied> { - using varied_type = typename lazy::varied; + using varied_type = varied>; auto syst = varied_type(this->nominal().filter(col.nominal())); @@ -3229,10 +3235,10 @@ auto queryosity::lazy::varied::filter(Col const &col) -> template template , bool>> -auto queryosity::lazy::varied::weight(Col const &col) -> - typename lazy::varied { +auto queryosity::varied>::weight(Col const &col) + -> varied> { - using varied_type = typename lazy::varied; + using varied_type = varied>; auto syst = varied_type(this->nominal().weight(col.nominal())); @@ -3246,13 +3252,13 @@ auto queryosity::lazy::varied::weight(Col const &col) -> template template , bool>> -auto queryosity::lazy::varied::filter( - queryosity::column::expression const &expr) -> - typename todo>>::varied { +auto queryosity::varied>::filter( + queryosity::column::expression const &expr) + -> varied< + todo>>> { - using varied_type = typename todo< - selection::applicator>>::varied; + using varied_type = varied< + todo>>>; auto syst = varied_type(this->nominal().filter(expr)); @@ -3265,14 +3271,13 @@ auto queryosity::lazy::varied::filter( template template , bool>> -auto queryosity::lazy::varied::weight( - queryosity::column::expression const &expr) -> - typename todo>>::varied { +auto queryosity::varied>::weight( + queryosity::column::expression const &expr) + -> varied>>> { - using varied_type = - typename todo>>::varied; + using varied_type = varied< + todo>>>; auto syst = varied_type(this->nominal().weight(expr)); @@ -3285,22 +3290,22 @@ auto queryosity::lazy::varied::weight( template template , bool>> -auto queryosity::lazy::varied::book(Agg &&agg) { +auto queryosity::varied>::book(Agg &&agg) { return agg.at(*this); } template template , bool>> -auto queryosity::lazy::varied::book(Aggs &&...aggs) { +auto queryosity::varied>::book(Aggs &&...aggs) { return std::make_tuple((aggs.at(*this), ...)); } template template , bool>> -auto queryosity::lazy::varied::operator[](const std::string &var_name) - -> lazy & { +auto queryosity::varied>::operator[]( + const std::string &var_name) -> queryosity::lazy & { if (!this->has_variation(var_name)) { throw std::out_of_range("variation does not exist"); } @@ -3310,8 +3315,8 @@ auto queryosity::lazy::varied::operator[](const std::string &var_name) template template , bool>> -auto queryosity::lazy::varied::operator[]( - const std::string &var_name) const -> lazy const & { +auto queryosity::varied>::operator[]( + const std::string &var_name) const -> queryosity::lazy const & { if (!this->has_variation(var_name)) { throw std::out_of_range("variation does not exist"); } @@ -3525,8 +3530,8 @@ template struct series { auto make(lazy &sel) const; - auto make(lazy::varied &sel) const -> - typename lazy>::varied; + auto make(varied> &sel) const -> + varied>>; protected: Col m_column; @@ -3553,8 +3558,8 @@ auto queryosity::column::series::make(lazy &sel) const { } template -auto queryosity::column::series::make(lazy::varied &sel) - const -> typename lazy>::varied { +auto queryosity::column::series::make(varied> &sel) + const -> varied>> { auto df = sel.nominal().m_df; return df->get(query::output>()) .fill(m_column) @@ -3677,7 +3682,7 @@ template template auto queryosity::lazy::filter(Col const &col) const { if constexpr (std::is_base_of_v) { - using varied_type = typename lazy::varied; + using varied_type = varied>; auto syst = varied_type(this->filter(col.nominal())); for (auto const &var_name : col.get_variation_names()) { syst.set_variation(var_name, this->filter(col.variation(var_name))); @@ -3693,7 +3698,7 @@ template template auto queryosity::lazy::weight(Col const &col) const { if constexpr (std::is_base_of_v) { - using varied_type = typename lazy::varied; + using varied_type = varied>; auto syst = varied_type(this->weight(col.nominal())); for (auto const &var_name : col.get_variation_names()) { syst.set_variation(var_name, this->weight(col.variation(var_name))); @@ -3755,8 +3760,7 @@ auto queryosity::lazy::get(queryosity::column::series const &col) template template , bool>> auto queryosity::lazy::get(queryosity::column::series const &col) - -> typename lazy< - query::series::value_type>>::varied { + -> varied::value_type>>> { return col.make(*this); } @@ -3855,7 +3859,7 @@ auto queryosity::dataset::loaded::vary( dataset::column const &col, std::map const &vars) { auto nom = this->read(col); - typename decltype(nom)::varied varied_column(std::move(nom)); + varied varied_column(std::move(nom)); for (auto const &var : vars) { varied_column.set_variation(var.first, this->read(dataset::column(var.second))); @@ -4144,8 +4148,8 @@ auto queryosity::dataflow::weight(lazy const &col) return this->_apply(col); } -template auto queryosity::dataflow::filter(Col const &col) { - using varied_type = typename lazy::varied; +template auto queryosity::dataflow::filter(varied const &col) { + using varied_type = varied>; varied_type syst(this->filter(col.nominal())); for (auto const &var_name : col.get_variation_names()) { syst.set_variation(var_name, this->filter(col.variation(var_name))); @@ -4153,8 +4157,8 @@ template auto queryosity::dataflow::filter(Col const &col) { return syst; } -template auto queryosity::dataflow::weight(Col const &col) { - using varied_type = typename lazy::varied; +template auto queryosity::dataflow::weight(varied const &col) { + using varied_type = varied>; varied_type syst(this->weight(col.nominal())); for (auto const &var_name : col.get_variation_names()) { syst.set_variation(var_name, this->weight(col.variation(var_name))); @@ -4272,9 +4276,9 @@ inline void queryosity::dataflow::reset() { m_analyzed = false; } template auto queryosity::dataflow::vary(column::constant const &cnst, std::map vars) -> - typename lazy>::varied { + varied>> { auto nom = this->define(cnst); - using varied_type = typename lazy>::varied; + using varied_type = varied>>; varied_type syst(std::move(nom)); for (auto const &var : vars) { this->_vary(syst, var.first, column::constant(var.second)); @@ -4287,9 +4291,9 @@ auto queryosity::dataflow::vary( column::expression const &expr, std::map::function_type> const &vars) -> - typename todo>>::varied { + varied>>> { auto nom = this->_equate(expr); - using varied_type = typename decltype(nom)::varied; + using varied_type = varied; using function_type = typename column::expression::function_type; varied_type syst(std::move(nom)); for (auto const &var : vars) { @@ -4302,9 +4306,9 @@ template auto queryosity::dataflow::vary( column::definition const &defn, std::map> const &vars) -> - typename todo>::varied { + varied>> { auto nom = this->_define(defn); - using varied_type = typename decltype(nom)::varied; + using varied_type = varied; varied_type syst(std::move(nom)); for (auto const &var : vars) { this->_vary(syst, var.first, var.second); @@ -4484,9 +4488,6 @@ class todo : public dataflow::node, public ensemble::slotted, public systematic::resolver> { -public: - class varied; - public: todo(dataflow &df, std::vector> bkr); virtual ~todo() = default; @@ -4496,12 +4497,14 @@ class todo : public dataflow::node, virtual std::vector const &get_slots() const final override; - virtual void set_variation(const std::string &var_name, todo var) final override; + virtual void set_variation(const std::string &var_name, + todo var) final override; virtual todo &nominal() final override; virtual todo &variation(const std::string &var_name) final override; virtual todo const &nominal() const final override; - virtual todo const &variation(const std::string &var_name) const final override; + virtual todo const & + variation(const std::string &var_name) const final override; virtual bool has_variation(const std::string &var_name) const final override; virtual std::set get_variation_names() const final override; @@ -4511,9 +4514,9 @@ class todo : public dataflow::node, * @param[in] columns Input columns. * @param[in][out] Evaluated column. */ - template , - bool> = false> + template < + typename... Nodes, typename V = Helper, + std::enable_if_t, bool> = false> auto evaluate(Nodes &&...columns) const -> decltype(std::declval>()._evaluate( std::forward(columns)...)) { @@ -4525,9 +4528,9 @@ class todo : public dataflow::node, * @param[in] columns Input columns. * @param[in][out] Applied selection. */ - template , - bool> = false> + template < + typename... Nodes, typename V = Helper, + std::enable_if_t, bool> = false> auto apply(Nodes &&...columns) const -> decltype(std::declval>()._apply( std::forward(columns)...)) { @@ -4540,8 +4543,7 @@ class todo : public dataflow::node, * @returns Updated query plan filled with input columns. */ template , - bool> = false> + std::enable_if_t, bool> = false> auto fill(Nodes &&...columns) const -> decltype(std::declval>()._fill(std::declval()...)) { return this->_fill(std::forward(columns)...); @@ -4573,13 +4575,12 @@ class todo : public dataflow::node, * @param[in] columns... Input columns. * @return Evaluated column. */ - template - auto operator()(Args &&...columns) const { - if constexpr( column::is_evaluatable_v ) { + template auto operator()(Args &&...columns) const { + if constexpr (column::is_evaluatable_v) { return this->evaluate(std::forward(columns)...); - } else if constexpr( selection::is_applicable_v ) { + } else if constexpr (selection::is_applicable_v) { return this->apply(std::forward(columns)...); - } else if constexpr( query::is_fillable_v ) { + } else if constexpr (query::is_fillable_v) { return this->fill(std::forward(columns)...); } } @@ -4598,10 +4599,11 @@ class todo : public dataflow::node, std::enable_if_t && queryosity::has_variation_v, bool> = false> - auto _evaluate(Nodes const &...columns) const -> - typename lazy>>>::varied { + auto _evaluate(Nodes const &...columns) const + -> varied>>>> { - using varied_type = typename lazy>>>::varied; + using varied_type = + varied>>>>; auto nom = this->m_df->_evaluate(*this, columns.nominal()...); auto syst = varied_type(std::move(nom)); @@ -4618,27 +4620,27 @@ class todo : public dataflow::node, std::enable_if_t && queryosity::has_no_variation_v, bool> = false> - auto _apply(Nodes const &...columns) const - -> lazy { + auto _apply(Nodes const &...columns) const -> lazy { using selection_type = typename V::selection_type; - return this->m_df->template _apply(*this,columns...); + return this->m_df->template _apply(*this, columns...); } template && queryosity::has_variation_v, bool> = false> - auto _apply(Nodes const &...columns) const -> - typename lazy::varied { + auto _apply(Nodes const &...columns) const -> varied> { using selection_type = typename V::selection_type; - using varied_type = typename lazy>::varied; + using varied_type = varied>>; - auto nom = this->m_df->template _apply(*this,columns.nominal()...); + auto nom = this->m_df->template _apply( + *this, columns.nominal()...); auto syst = varied_type(std::move(nom)); for (auto const &var_name : systematic::get_variation_names(columns...)) { - auto var = this->m_df->template _apply(*this,columns.variation(var_name)...); + auto var = this->m_df->template _apply( + *this, columns.variation(var_name)...); syst.set_variation(var_name, std::move(var)); } @@ -4657,9 +4659,8 @@ class todo : public dataflow::node, std::enable_if_t && queryosity::is_varied_v, bool> = false> - auto _book(Node const &sel) const -> - typename lazy>::varied { - using varied_type = typename lazy>::varied; + auto _book(Node const &sel) const -> varied>> { + using varied_type = varied>>; auto syst = varied_type(this->m_df->_book(*this, sel.nominal())); for (auto const &var_name : systematic::get_variation_names(sel)) { syst.set_variation(var_name, @@ -4683,11 +4684,9 @@ class todo : public dataflow::node, has_variation_v, bool> = false> auto _book(Nodes const &...sels) const - -> std::array>::varied, - sizeof...(Nodes)> { - using varied_type = typename lazy>::varied; - using array_of_varied_type = - std::array>::varied, sizeof...(Nodes)>; + -> std::array>>, sizeof...(Nodes)> { + using varied_type = varied>>; + using array_of_varied_type = std::array; auto var_names = systematic::get_variation_names(sels...); auto _book_varied = [var_names, @@ -4719,8 +4718,9 @@ class todo : public dataflow::node, std::enable_if_t && has_variation_v, bool> = false> - auto _fill(Nodes const &...columns) const -> varied { - auto syst = varied(std::move(this->_fill(columns.nominal()...))); + auto _fill(Nodes const &...columns) const -> varied> { + using varied_type = varied>; + auto syst = varied_type(std::move(this->_fill(columns.nominal()...))); for (auto const &var_name : systematic::get_variation_names(columns...)) { syst.set_variation( var_name, std::move(this->_fill(columns.variation(var_name)...))); @@ -4757,13 +4757,15 @@ void queryosity::todo::set_variation(const std::string &, throw std::logic_error("cannot set variation to a nominal-only action"); } -template auto queryosity::todo::nominal() -> todo & { +template +auto queryosity::todo::nominal() -> todo & { // this is nominal return *this; } template -auto queryosity::todo::variation(const std::string &) -> todo & { +auto queryosity::todo::variation(const std::string &) + -> todo & { // propagation of variations must occur "transparently" return *this; } @@ -4986,7 +4988,7 @@ namespace queryosity { * corresponding to nominal and systematic variations. */ template -class todo::varied : public dataflow::node, +class varied> : public dataflow::node, systematic::resolver> { public: @@ -4996,12 +4998,14 @@ class todo::varied : public dataflow::node, varied(varied &&) = default; varied &operator=(varied &&) = default; - virtual void set_variation(const std::string &var_name, todo var) final override; + virtual void set_variation(const std::string &var_name, + todo var) final override; - virtual todo &nominal() final override; - virtual todo &variation(const std::string &var_name) final override; - virtual todo const &nominal() const final override; - virtual todo const &variation(const std::string &var_name) const final override; + virtual todo &nominal() final override; + virtual todo &variation(const std::string &var_name) final override; + virtual todo const &nominal() const final override; + virtual todo const & + variation(const std::string &var_name) const final override; virtual bool has_variation(const std::string &var_name) const final override; virtual std::set get_variation_names() const final override; @@ -5010,14 +5014,13 @@ class todo::varied : public dataflow::node, template < typename... Cols, typename V = Helper, std::enable_if_t, bool> = false> - auto evaluate(Cols &&...cols) -> typename decltype(this->nominal().evaluate( - std::forward(cols.nominal)...))::varied; + auto evaluate(Cols &&...cols) -> varied< + decltype(this->nominal().evaluate(std::forward(cols.nominal)...))>; template < typename... Cols, typename V = Helper, std::enable_if_t, bool> = false> - auto apply(Cols &&...cols) -> - typename queryosity::lazy>::varied; + auto apply(Cols &&...cols) -> varied>>; /** * @brief Fill the query with input columns. @@ -5035,7 +5038,7 @@ class todo::varied : public dataflow::node, */ template , bool> = false> - auto at(Node const &selection) -> typename lazy>::varied; + auto at(Node const &selection) -> varied>>; /** * @brief Book the query at multiple selections. @@ -5045,13 +5048,12 @@ class todo::varied : public dataflow::node, template , bool> = false> auto at(Nodes const &...selections) - -> std::array>::varied, - sizeof...(Nodes)>; + -> std::array>>, sizeof...(Nodes)>; template - auto operator()(Cols &&...cols) -> - typename decltype(std::declval>().operator()( - std::forward(cols).nominal()...))::varied; + auto operator()(Cols &&...cols) + -> varied>().operator()( + std::forward(cols).nominal()...))>; protected: todo m_nominal; @@ -5062,60 +5064,62 @@ class todo::varied : public dataflow::node, } // namespace queryosity template -queryosity::todo::varied::varied(todo &&nom) +queryosity::varied>::varied( + queryosity::todo &&nom) : dataflow::node(*nom.m_df), m_nominal(std::move(nom)) {} template -void queryosity::todo::varied::set_variation( - const std::string &var_name, todo var) { +void queryosity::varied>::set_variation( + const std::string &var_name, queryosity::todo var) { m_variation_map.insert(std::move(std::make_pair(var_name, std::move(var)))); m_variation_names.insert(var_name); } template -auto queryosity::todo::varied::nominal() -> todo & { +auto queryosity::varied>::nominal() -> todo & { return m_nominal; } template -auto queryosity::todo::varied::nominal() const -> todo const & { +auto queryosity::varied>::nominal() const + -> todo const & { return m_nominal; } template -auto queryosity::todo::varied::variation(const std::string &var_name) - -> todo & { +auto queryosity::varied>::variation( + const std::string &var_name) -> todo & { return (this->has_variation(var_name) ? m_variation_map.at(var_name) : m_nominal); } template -auto queryosity::todo::varied::variation( - const std::string &var_name) const -> todo const & { +auto queryosity::varied>::variation( + const std::string &var_name) const -> todo const & { return (this->has_variation(var_name) ? m_variation_map.at(var_name) : m_nominal); } template -bool queryosity::todo::varied::has_variation( +bool queryosity::varied>::has_variation( const std::string &var_name) const { return m_variation_map.find(var_name) != m_variation_map.end(); } template std::set -queryosity::todo::varied::get_variation_names() const { +queryosity::varied>::get_variation_names() const { return m_variation_names; } template template , bool>> -auto queryosity::todo::varied::evaluate(Cols &&...cols) -> - typename decltype(this->nominal().evaluate( - std::forward(cols.nominal)...))::varied { - using varied_type = typename decltype(this->nominal().evaluate( - std::forward(cols.nominal)...))::varied; +auto queryosity::varied>::evaluate(Cols &&...cols) + -> variednominal().evaluate( + std::forward(cols.nominal)...))> { + using varied_type = variednominal().evaluate( + std::forward(cols.nominal)...))>; auto syst = varied_type( this->nominal().evaluate(std::forward(cols).nominal()...)); for (auto const &var_name : @@ -5130,10 +5134,9 @@ auto queryosity::todo::varied::evaluate(Cols &&...cols) -> template template , bool>> -auto queryosity::todo::varied::apply(Cols &&...cols) -> - typename queryosity::lazy>::varied { - using varied_type = - typename queryosity::lazy>::varied; +auto queryosity::varied>::apply(Cols &&...cols) + -> varied>> { + using varied_type = varied>>; auto syst = varied_type(this->nominal().apply(std::forward(cols).nominal()...)); for (auto const &var_name : @@ -5148,7 +5151,8 @@ auto queryosity::todo::varied::apply(Cols &&...cols) -> template template , bool>> -auto queryosity::todo::varied::fill(Nodes const &...columns) -> varied { +auto queryosity::varied>::fill(Nodes const &...columns) + -> varied { auto syst = varied(std::move(this->nominal().fill(columns.nominal()...))); for (auto const &var_name : systematic::get_variation_names(*this, columns...)) { @@ -5161,9 +5165,9 @@ auto queryosity::todo::varied::fill(Nodes const &...columns) -> varied { template template , bool>> -auto queryosity::todo::varied::at(Node const &selection) -> - typename lazy>::varied { - using varied_type = typename lazy>::varied; +auto queryosity::varied>::at(Node const &selection) + -> varied>> { + using varied_type = varied>>; auto syst = varied_type(this->nominal().at(selection.nominal())); for (auto const &var_name : systematic::get_variation_names(*this, selection)) { @@ -5176,12 +5180,13 @@ auto queryosity::todo::varied::at(Node const &selection) -> template template , bool>> -auto queryosity::todo::varied::at(Nodes const &...selections) - -> std::array>::varied, sizeof...(Nodes)> { +auto queryosity::varied>::at( + Nodes const &...selections) + -> std::array>>, sizeof...(Nodes)> { // variations - using varied_type = typename lazy>::varied; + using varied_type = varied>>; using array_of_varied_type = - std::array>::varied, sizeof...(Nodes)>; + std::array>>, sizeof...(Nodes)>; auto var_names = systematic::get_variation_names(*this, selections...); auto _book_varied = [var_names, @@ -5198,12 +5203,12 @@ auto queryosity::todo::varied::at(Nodes const &...selections) template template -auto queryosity::todo::varied::operator()(Cols &&...cols) -> - typename decltype(std::declval>().operator()( - std::forward(cols).nominal()...))::varied { +auto queryosity::varied>::operator()(Cols &&...cols) + -> varied>().operator()( + std::forward(cols).nominal()...))> { - using varied_type = typename decltype(std::declval>().operator()( - std::forward(cols).nominal()...))::varied; + using varied_type = varied>().operator()( + std::forward(cols).nominal()...))>; auto syst = varied_type( this->nominal().operator()(std::forward(cols).nominal()...)); @@ -5238,7 +5243,7 @@ auto queryosity::systematic::vary(systematic::nominal const &nom, using action_type = typename Lzy::action_type; using value_type = column::value_t; using nominal_type = lazy>; - using varied_type = typename nominal_type::varied; + using varied_type = varied; varied_type syst(nom.get().template to()); (syst.set_variation(vars.name(), vars.get().template to()), ...); return syst;