tables::ftable::fupdate

template <is_table T,is_tuple_unique Gs>
template<typename... Ss,typename... Fs>
requires (
  (sizeof...(Ss) == sizeof...(Fs))
  && ( all_in<std::tuple<Ss...>,tuple_ext::remove_t<Gs,typename T::ts_t>> )
  && ( is_col_to_col_f<Fs,typename T::p_of_t<Ss>> && ... )
)
auto
ftable<T,Gs>::fupdate(const Fs... fs) const

Applies transformation function to groups.

Example

Code

#include <cpptables/table.hh>
#include <iostream>

using namespace tables;
using namespace std;

struct col0  { constexpr static char const * const name = "col0"; };
struct col1  { constexpr static char const * const name = "col1"; };
struct col2  { constexpr static char const * const name = "col2"; };

using table_t = table<
  pair<col0,string_view>,
  pair<col1,unsigned>,
  pair<col2,double>
>;

void fby_fupdate()
{
  const table_t t(
    {"A", "B", "C", "A", "B", "C", "A", "B", "C"},
    {1,10,100,2,20,200,3,30,300},
    {100.0,200.0,300.0,400.0,500.0,600.0,700.0,800.0,900.0}
  );

  const auto freverse = [](const column<auto>& xs) { return xs.reverse(); };
  const auto t1 = t.fby<col0>().fupdate<col1>(freverse);
  cout << t1 << "\n";

  const auto fdup = [](const column<double>& xs) { return xs * 2.0; };
  const auto t2 = t1.fby<col0>().fupdate<col2>(fdup);
  cout << t2 << "\n";
}

Output

col0 col1 col2
--------------
   A    3  100
   B   30  200
   C  300  300
   A    2  400
   B   20  500
   C  200  600
   A    1  700
   B   10  800
   C  100  900

col0 col1 col2
--------------
   A    3  200
   B   30  400
   C  300  600
   A    2  800
   B   20 1000
   C  200 1200
   A    1 1400
   B   10 1600
   C  100 1800