diff --git a/db/attribute_group_iterator_impl.h b/db/attribute_group_iterator_impl.h index 3977fe4282..7f73ec7cc9 100644 --- a/db/attribute_group_iterator_impl.h +++ b/db/attribute_group_iterator_impl.h @@ -16,11 +16,8 @@ class AttributeGroupIteratorImpl : public AttributeGroupIterator { const Comparator* comparator, const std::vector& column_families, const std::vector& child_iterators) - : impl_( - comparator, column_families, child_iterators, [this]() { Reset(); }, - [this](const autovector& items) { - AddToAttributeGroups(items); - }) {} + : impl_(comparator, column_families, child_iterators, ResetFunc(this), + PopulateFunc(this)) {} ~AttributeGroupIteratorImpl() override {} // No copy allowed @@ -46,7 +43,33 @@ class AttributeGroupIteratorImpl : public AttributeGroupIterator { void Reset() { attribute_groups_.clear(); } private: - MultiCfIteratorImpl impl_; + class ResetFunc { + public: + explicit ResetFunc(AttributeGroupIteratorImpl* iter) : iter_(iter) {} + + void operator()() const { + assert(iter_); + iter_->Reset(); + } + + private: + AttributeGroupIteratorImpl* iter_; + }; + + class PopulateFunc { + public: + explicit PopulateFunc(AttributeGroupIteratorImpl* iter) : iter_(iter) {} + + void operator()(const autovector& items) const { + assert(iter_); + iter_->AddToAttributeGroups(items); + } + + private: + AttributeGroupIteratorImpl* iter_; + }; + + MultiCfIteratorImpl impl_; IteratorAttributeGroups attribute_groups_; void AddToAttributeGroups(const autovector& items); }; diff --git a/db/coalescing_iterator.h b/db/coalescing_iterator.h index a4d156a6da..a760d3f40b 100644 --- a/db/coalescing_iterator.h +++ b/db/coalescing_iterator.h @@ -15,11 +15,8 @@ class CoalescingIterator : public Iterator { CoalescingIterator(const Comparator* comparator, const std::vector& column_families, const std::vector& child_iterators) - : impl_( - comparator, column_families, child_iterators, [this]() { Reset(); }, - [this](const autovector& items) { - Coalesce(items); - }) {} + : impl_(comparator, column_families, child_iterators, ResetFunc(this), + PopulateFunc(this)) {} ~CoalescingIterator() override {} // No copy allowed @@ -51,7 +48,33 @@ class CoalescingIterator : public Iterator { } private: - MultiCfIteratorImpl impl_; + class ResetFunc { + public: + explicit ResetFunc(CoalescingIterator* iter) : iter_(iter) {} + + void operator()() const { + assert(iter_); + iter_->Reset(); + } + + private: + CoalescingIterator* iter_; + }; + + class PopulateFunc { + public: + explicit PopulateFunc(CoalescingIterator* iter) : iter_(iter) {} + + void operator()(const autovector& items) const { + assert(iter_); + iter_->Coalesce(items); + } + + private: + CoalescingIterator* iter_; + }; + + MultiCfIteratorImpl impl_; Slice value_; WideColumns wide_columns_; diff --git a/db/multi_cf_iterator_impl.h b/db/multi_cf_iterator_impl.h index 46f397cc4d..b487211092 100644 --- a/db/multi_cf_iterator_impl.h +++ b/db/multi_cf_iterator_impl.h @@ -21,14 +21,13 @@ struct MultiCfIteratorInfo { int order; }; +template class MultiCfIteratorImpl { public: - MultiCfIteratorImpl( - const Comparator* comparator, - const std::vector& column_families, - const std::vector& child_iterators, - std::function reset_func, - std::function&)> populate_func) + MultiCfIteratorImpl(const Comparator* comparator, + const std::vector& column_families, + const std::vector& child_iterators, + ResetFunc reset_func, PopulateFunc populate_func) : comparator_(comparator), heap_(MultiCfMinHeap( MultiCfHeapItemComparator>(comparator_))), @@ -136,8 +135,8 @@ class MultiCfIteratorImpl { MultiCfIterHeap heap_; - std::function reset_func_; - std::function)> populate_func_; + ResetFunc reset_func_; + PopulateFunc populate_func_; Iterator* current() const { if (std::holds_alternative(heap_)) { @@ -163,11 +162,11 @@ class MultiCfIteratorImpl { } void InitMinHeap() { - heap_.emplace( + heap_.template emplace( MultiCfHeapItemComparator>(comparator_)); } void InitMaxHeap() { - heap_.emplace( + heap_.template emplace( MultiCfHeapItemComparator>(comparator_)); }