tables::table::sort_by

1)

template <typename... Ts,is_primitive_type... Ps>
template<typename... Ss>
requires (
  (in<Ss,std::tuple<Ts...>> && ... ) &&
  is_tuple_unique<std::tuple<Ss...>>
)
inline
table<std::pair<Ts,Ps>...>
table<std::pair<Ts,Ps>...>::sort_by() const

2)

template <typename... Ts,is_primitive_type... Ps>
template<tuple_ext::is_tuple Ss>
requires ( all_in<Ss,std::tuple<Ts...>> && is_tuple_unique<Ss>)
inline
table<std::pair<Ts,Ps>...>
table<std::pair<Ts,Ps>...>::sort_by() const

Return table with rows sorted by selected columns.

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,char>,
  pair<c2,unsigned>
>;

void table_sort_by()
{
  const table_t t(
      {"foo","abc","zoo","abc"},
      {'a','b','c','d'},
      {1,2,3,4}
    );
  
  cout << t.sort_by<c0,c1>() << "\n";
}

Output

Col0 Col1 Col2
--------------
 abc    b    2
 abc    d    4
 foo    a    1
 zoo    c    3