mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-10-30 16:07:38 +08:00
allow passing move-only parameter to Make() (#338)
ftxui::Ref<> is used for passing Options, for instance, MenuOption, to the corresponding component which is supposed to hold a strong reference of it. and we can observe the events sent to the component by setting callback(s) in the option instance passed to the owner component. but the callback function is not always copyable, despite that it might be moveable. in this change, * Make<>() is updated to use the perfect forwarding to avoid enforcing its parameters to be copyable. * Ref<> is also updated to take a rvalue reference, so we can move away from the contructor parameter when creating an instance of Ref<>() from it. Signed-off-by: Kefu Chai <tchaikov@gmail.com>
This commit is contained in:
parent
9b83205b3e
commit
63e8dadad9
@ -23,7 +23,7 @@ struct MenuEntryOption;
|
||||
|
||||
template <class T, class... Args>
|
||||
std::shared_ptr<T> Make(Args&&... args) {
|
||||
return std::make_shared<T>(args...);
|
||||
return std::make_shared<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
namespace Container {
|
||||
|
@ -27,7 +27,8 @@ template <typename T>
|
||||
class Ref {
|
||||
public:
|
||||
Ref() {}
|
||||
Ref(T t) : owned_(t) {}
|
||||
Ref(const T& t) : owned_(t) {}
|
||||
Ref(T&& t) : owned_(std::forward<T>(t)) {}
|
||||
Ref(T* t) : address_(t) {}
|
||||
T& operator*() { return address_ ? *address_ : owned_; }
|
||||
T& operator()() { return address_ ? *address_ : owned_; }
|
||||
|
Loading…
Reference in New Issue
Block a user