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 months ago
parent
commit
8c2cef7b27
1 changed files with 21 additions and 1 deletions
  1. +21
    -1
      src/wrapper.hh

+ 21
- 1
src/wrapper.hh View File

@ -13,6 +13,8 @@ template<class T>
class Wrapper
{
public:
typedef T c_type;
template<class... Args>
Wrapper(Args... args) : value{ this->_new(args...) } {}
@ -28,6 +30,9 @@ public:
Wrapper<T> copy() const;
friend
bool operator==(const Wrapper<T>& a, const Wrapper<T>& b);
private:
// must be defined for each wrapped type:
template<class... Args>
@ -42,6 +47,8 @@ template<class T>
class Wrapper<T*>
{
public:
typedef T* c_type;
Wrapper() : value{nullptr} {}
template<class... Args>
@ -70,6 +77,11 @@ public:
_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:
@ -84,6 +96,13 @@ protected:
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
// to std::forward_list
@ -114,8 +133,9 @@ public:
// I am my own iterator
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 push_back(Element&&);


Loading…
Cancel
Save