tables::gtable::n_groups

template <typename... Ts,is_primitive_type... Ps,typename... Gs>
typename gtable<table<std::pair<Ts,Ps>...>,std::tuple<Gs...>>::map_t
gtable<table<std::pair<Ts,Ps>...>,std::tuple<Gs...>>::m() const

Returns underlyung map.

Example

Code

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

using namespace tables;
using namespace std;

struct c0{ constexpr static string_view name =  "Col0"; };
struct c1{ constexpr static string_view name =  "Col1"; };
struct c2{ constexpr static string_view name =  "Col2"; };

using table_t = table<
  pair<c0,string_view>,
  pair<c1,unsigned>,
  pair<c2,double>
>;


void gtable_m()
{
  const table_t t(
      {"abc", "def", "ghi", "abc", "def", "ghi"},
      {100,200,300,400,500,600},
      {1.0,2.0,3.0,4.0,5.0,6.0}
    );

  using gtable_t = table_t::group_by_t<tuple<c0>>;
  const gtable_t gt = t.group_by<c0>();
  for ( const auto& p : gt.m() )
  {
    cout << "row:\n" << p.first << "\n"; 
    cout << "table:\n" << p.second << "\n"; 
    cout << "\n";
  }
}

Output

row:
Col0
-----
  abc

table:
Col1 Col2
---------
 100    1
 400    4


row:
Col0
-----
  def

table:
Col1 Col2
---------
 200    2
 500    5

row:
Col0
-----
 ghi

table:
Col1 Col2
---------
 300    3
 600    6