Re: Replace Gtk::manage() with std::unique_ptr<>?



On Mon, 2016-02-08 at 20:04 +0100, Jonas Platte wrote:
So, I've read most of this conversation, and it seems this simple
alternative hasn't come up yet:

  // Old code
  auto button = Gtk::manage(new Gtk::Button("a button");
  button->show();
  container.add(button);

  // New code
  auto button = container.add_managed<Gtk::Button>("a button");
  button->show();

I don't know how feasible it is to create loads of new member
functions
with a _managed (or a different) suffix, but API-wise I think
reducing
the creation and insertion into the container to one statement would
make sense with std::unique_ptr.

Thanks. But that wouldn't involve a std::unique_ptr<> at all. It
doesn't feel much different than what we have with Gtk::manage().

It also forces the add() to to the beginning. I tend to prefer doing
that at the end, after setting up the child widget. I generally assume
that changing the state of the child after it is in a container might
trigger useless processing which I could avoid by doing it before
adding it to the container.

Allowing use of unique_ptr<> seems more flexible.

-- 
Murray Cumming
murrayc murrayc com
www.murrayc.com





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]