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] better format, print + as opt-in #134

Open
1 task done
GuillaumeDua opened this issue Oct 4, 2023 · 0 comments · May be fixed by #241
Open
1 task done

[ag] better format, print + as opt-in #134

GuillaumeDua opened this issue Oct 4, 2023 · 0 comments · May be fixed by #241
Assignees
Labels
dev - refactoring dev - refactoring
Milestone

Comments

@GuillaumeDua
Copy link
Owner

GuillaumeDua commented Oct 4, 2023

Dependencies


Pocs


📘💡Design

API:

csl::ag::concepts::aggregate auto value = /* some aggregate value */;

csl::ag::io::join<opt_ins...>(value , presentation);

// vs.
fmt::println("{}", csl::ag::io::join<presentation::indented>(value))
fmt::println("{}", value | join<presentation::indented>)
fmt::println("{}", value | indexed | typenamed | join<presentation>);

Call: split formatting style and join_view, see #262 , #263

  • formatting style : produces opening/closing bracket, separator
    • none
    • compact
    • indented
  • join_view composition => delegated formatters modifiers (formatters of proxy types)

📘💡 Back to design:

📘💡Back to design (2):

Implementation design:

// simple formatter
struct fmt::formatter<csl::ag::concepts::aggregate>{}; // parse {} or {:n}
struct fmt::formatter<join_view<csl::ag::concepts::aggregate>>{};

template <std::size_t depth> struct presentation_factory; // -> as tttp
fmt::println("value = {}", csl::ag::io::join<presentation::indented>(value))
    
// indexed<T> -> std::index_sequence<csl::ag::size_v | std::tuple_size_v>, or std::views::enumerate
// typenamed<T> - with detection not T::csl_ag_io_product

fmt::println("value = {}", csl::ag::io::join<presentation::indented>(
   indexed{ typenamed { value } }
))
fmt::println("{}", value | indexed | typenamed | join<presentation>)

Recursive lambda quick impl:

 const auto printer = overload{
      [](const auto & self, std::size_t depth, const csl::ag::concepts::aggregate auto & value){
          fmt::println("{:\t>{}}{{", "", depth);
          using type = std::remove_cvref_t<decltype(value)>;
          [&]<std::size_t ... indexes>(std::index_sequence<indexes...>){
              ((std::invoke(
                  self,
                  self, depth + 1, csl::ag::get<indexes>(value)
              ), ...));
          }(std::make_index_sequence<csl::ag::size_v<type>>{});
          fmt::println("{:\t>{}}}}", "", depth);
      },
      [](const auto & /* self */, std::size_t depth, const auto & value){
          fmt::println("{:\t>{}}{}", "", depth, value);
      }
  };

  printer(printer, 0, value);

💡 Ideas

💡 views composition join_view<strategies...>

see #262

struct A{ int i; };
struct B{ A a; char c; }

csl::ag::join_view<typenamed, indented /*etc...*/>(B{}, ",");

💡 Idea : flatten, rewrap<T is aggregate ? view<aggregate> : T>

see #263

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev - refactoring dev - refactoring
Projects
Status: In progress
Development

Successfully merging a pull request may close this issue.

1 participant