From df7e02856c629c3f6b2c09374d0fd3c4f3897467 Mon Sep 17 00:00:00 2001 From: "Tim.Ebbeke" Date: Thu, 17 Aug 2023 17:39:45 +0200 Subject: [PATCH] Added missing insert function for sets. --- .../frontend/event_system/observed_value.hpp | 32 +++++++++++++++++-- .../event_system/range_event_context.hpp | 4 +++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/nui/include/nui/frontend/event_system/observed_value.hpp b/nui/include/nui/frontend/event_system/observed_value.hpp index 8164b51..e0f8335 100644 --- a/nui/include/nui/frontend/event_system/observed_value.hpp +++ b/nui/include/nui/frontend/event_system/observed_value.hpp @@ -711,6 +711,30 @@ namespace Nui rangeContext_.reset(0, true); update(); } + template + Detail::PickFirst_t< + std::pair, + decltype(std::declval().insert(std::declval()))> + insert(const value_type& value) + { + const auto result = contained_.insert(value); + rangeContext_.performFullRangeUpdate(); + update(); + globalEventContext.executeActiveEventsImmediately(); + return result; + } + template + Detail::PickFirst_t< + std::pair, + decltype(std::declval().insert(std::declval()))> + insert(value_type&& value) + { + const auto result = contained_.insert(std::move(value)); + rangeContext_.performFullRangeUpdate(); + update(); + globalEventContext.executeActiveEventsImmediately(); + return result; + } iterator insert(iterator pos, const value_type& value) { return insert(pos.getWrapped(), value); @@ -805,12 +829,16 @@ namespace Nui insertRangeChecked(distance, distance + std::distance(first, last), RangeStateType::Erase); return iterator{this, it}; } - void push_back(const value_type& value) + template + Detail::PickFirst_t().push_back(std::declval()))> + push_back(const value_type& value) { contained_.push_back(value); insertRangeChecked(size() - 1, size() - 1, RangeStateType::Insert); } - void push_back(value_type&& value) + template + Detail::PickFirst_t().push_back(std::declval()))> + push_back(value_type&& value) { contained_.push_back(std::move(value)); insertRangeChecked(size() - 1, size() - 1, RangeStateType::Insert); diff --git a/nui/include/nui/frontend/event_system/range_event_context.hpp b/nui/include/nui/frontend/event_system/range_event_context.hpp index 1fef557..840aa4a 100644 --- a/nui/include/nui/frontend/event_system/range_event_context.hpp +++ b/nui/include/nui/frontend/event_system/range_event_context.hpp @@ -202,6 +202,10 @@ namespace Nui Accepted, // Accepted, update can be deferred. Retry // Must update immediately and reissue this. }; + void performFullRangeUpdate() + { + fullRangeUpdate_ = true; + } InsertResult insertModificationRange(long elementCount, long low, long high, RangeStateType type) { if (disableOptimizations_)