C ++ polymorphe Iteratoren in abstrakter Basisklasse mit benutzerdefinierten Kinderimplementierungen

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: C ++ polymorphe Iteratoren in abstrakter Basisklasse mit benutzerdefinierten Kinderimplementierungen

by Anonymous » 26 Aug 2025, 08:31

Ich arbeite an einem C ++ - Projekt, bei dem ich einen abstrakten Basisklassenspeicher habe, der einen Container mit Bin -Objekte darstellt. Jede Unterklasse von Store (z. B. Densestore , SparseStore ) verwendet ein anderes internes Datenlayout, um seine nicht leeren Bins zu speichern.

Code: Select all

template
class Store {
public:
using allocator_type = Allocator;

virtual ~Store() = default;
virtual void add(int index) = 0;
virtual void add(int index, uint64_t count) = 0;
virtual void add(const Bin& bin) = 0;
virtual Store* copy() const = 0;
virtual void clear() = 0;
virtual bool is_empty() const = 0;
virtual int get_max_index() const = 0;
virtual int get_min_index() const = 0;
virtual uint64_t get_total_count() const = 0;
virtual void merge(const Store& other) = 0;

// Iterators
using const_iterator = ???;
virtual const_iterator begin() const = 0;
virtual const_iterator end() const = 0;

using const_reverse_iterator = ???;
virtual const_reverse_iterator rbegin() const = 0;
virtual const_reverse_iterator rend() const = 0;
};

Gibt es eine saubere, idiomatische Möglichkeit, in diesem Fall eine polymorphe Iteration im STL-Stil zu implementieren? Rückgabe von std :: Unique_ptr von begin () und end () . Es funktioniert, aber es ist hässlich und nicht mit STL -Algorithmen kompatibel>

Top