Skip to content

Ref, ConstRef, StringRef and other adapters #339

Answered by ArthurSonzogni
mark2185 asked this question in Q&A
Discussion options

You must be logged in to vote

Couldn't you pass by value and have a getter that returns a reference? Godbolt example.

It is essential for the component to be able not to "own" the data.

For instance, let say you to implement a tab bar, displaying multiple subcomponent, depending on the value selected.

  std::vector<std::string> tab_values{"tab_1", "tab_2", "tab_3"};
  int tab_selected = 0;
  auto tab_toggle = Toggle(&tab_values, &tab_selected);

  auto tab_container = Container::Tab({
          [...] // Component for tab 1.
          [...] // Component for tab 2.
          [...] // Component for tab 3.
      },
      &tab_selected);

  auto final_component = Container::Vertical({
      tab_toggle,
      tab_containe…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@mark2185
Comment options

Comment options

You must be logged in to vote
1 reply
@mark2185
Comment options

Answer selected by mark2185
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants