Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ag] fmt::formatter view composition #262

Open
GuillaumeDua opened this issue Oct 3, 2024 · 0 comments
Open

[ag] fmt::formatter view composition #262

GuillaumeDua opened this issue Oct 3, 2024 · 0 comments
Assignees

Comments

@GuillaumeDua
Copy link
Owner

GuillaumeDua commented Oct 3, 2024

Part of #134

Motivation

Combine several modifiers to print csl::ag::concepts::aggregate in a specific ways

  • indexed: incremental indexes... of each element
  • typenamed: prefix each value with element csl::typeinfo::typename...
  • indented_view ? (depth-based indentation)
  • TBD.
fmt::println("{}", csl::ag::io::join<indexed, typenamed>(value)); // aggregate_join_view<indexed_t, typenamed_t>

Requires proper dispatching to underlying formatters.

POCs/Design

Question: infos-dedicated type.s dispatch ?

template <typename T>
struct meta_infos : std::type_identity<T> {};
template <typename T>
struct meta_infos_range : std::type_identity<T> {
    std::size_t index = 0;
};
template <typename T, std::size_t index>
struct meta_infos_tuple : std::type_identity<T> {
   constexpr inline static std::size_t index = index;
};

Question: should style information be part of the parse instead ?

  • pros: indented<style>
  • cons: inconsistent with fmt::formatters of range and tuple_like

Details/examples

  • {:n}: none
  • {:c}: compact (default)
  • {:i}: indented -> requires constexpr string - constexpr std::basic_string(count, char)

so for instance:

struct A{ int i = 42; char c = 'c'; };
struct B{ bool b = true; A a; };

fmt::println("{:n}", B{}); // { true42c }
fmt::println("{:c}", B{}); // { true, { 42, c } }
fmt::println("{:i}", B{});
// {
//   true,
//   {
//     42,
//     c
//   }
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In progress
Development

No branches or pull requests

1 participant