Browse Source

okay, it does not work this way: iterators are copied often, but the main Wrapper<T> shall not be copyable.

master
roker 4 years ago
parent
commit
8c2cef7b27
  1. 22
      src/wrapper.hh

22
src/wrapper.hh

@ -13,6 +13,8 @@ template<class T>
class Wrapper class Wrapper
{ {
public: public:
typedef T c_type;
template<class... Args> template<class... Args>
Wrapper(Args... args) : value{ this->_new(args...) } {} Wrapper(Args... args) : value{ this->_new(args...) } {}
@ -28,6 +30,9 @@ public:
Wrapper<T> copy() const; Wrapper<T> copy() const;
friend
bool operator==(const Wrapper<T>& a, const Wrapper<T>& b);
private: private:
// must be defined for each wrapped type: // must be defined for each wrapped type:
template<class... Args> template<class... Args>
@ -42,6 +47,8 @@ template<class T>
class Wrapper<T*> class Wrapper<T*>
{ {
public: public:
typedef T* c_type;
Wrapper() : value{nullptr} {} Wrapper() : value{nullptr} {}
template<class... Args> template<class... Args>
@ -70,6 +77,11 @@ public:
_free(value); _free(value);
} }
const T* get() const { return value; }
T* move_out() && { T* r = value; value=nullptr; return r;}
friend
bool operator==(const Wrapper<T*>& a, const Wrapper<T*>& b);
protected: protected:
@ -84,6 +96,13 @@ protected:
T* value; T* value;
}; };
template<class T>
inline
bool operator!=(const Wrapper<T>& a, const Wrapper<T>& b)
{
return !(a==b);
}
// Wraps single-linked lists and provides an interface compatible // Wraps single-linked lists and provides an interface compatible
// to std::forward_list // to std::forward_list
@ -114,8 +133,9 @@ public:
// I am my own iterator // I am my own iterator
iterator operator++() { return (value ? value = value->next : value); } iterator operator++() { return (value ? value = value->next : value); }
Element operator*() { return value->Value; } Element operator*() { return value->*Value; }
void erase(const iterator& it);
void clear(); void clear();
void push_back(Element&&); void push_back(Element&&);

Loading…
Cancel
Save