Some additional thoughts:
1) Using std::shared_ptr encourages me, to use the pointer multible times in
the same way. But this is not OK here.
auto button = std::make_shared<Gtk::Button>("a button");
{
Gtk::Frame frame;
frame.add(button); // OK
button.set_label("text"); // OK
}
{
Gtk::Frame frame2;
frame2.add(button); // not OK, if button is destroyed with the destruction
of frame
button.set_label("text");
}
2) We could use a new pointer type, containing a pointer and a boolean
(managed or not managed). So (pointer, true) is like std::unique, (pointer,
false) is like a raw pointer.
auto button = Gtk::managed_ptr<Gtk::Button>("a button"); // (pointer, true)
{
Gtk::Frame frame;
frame.add(button); // converts button to (pointer, false)
button.set_label("text"); // OK
}
{
Gtk::Frame frame2;
frame2.add(button); // run time error, since button is like a raw pointer
button.set_label("text");
}
But this means, we do not use an existing model from the standard library.
Also the error using the button twice will be a runtime error, not a compile
time error.
3)
container.add(std::make_unique<Gtk::Button>("a button"));
auto button = container.get();
button.set_label("text");
Which type will button be? As programmer, I want it to be a Button* or
comparable. I do not think, it is possible to return the exact type without
specifying it a second time like
auto button = container.get<Gtk::Button*>();
DietherAttachment:
signature.asc
Description: This is a digitally signed message part.