mardi 12 février 2019

Can a pointer move itself to a container?

I have the following interface:

struct Interface {
  Interface(const Interface &) = delete;
  auto operator=(const Interface &) -> Interface & = delete;
  ~Interface() = 0;
  protected:
    Interface() = default;
};

And an implementation:

struct Implementation : public Interface {
  Implementation(Pool &p) : m_pool{p} {}
};

I also have a pool of Implementations:

struct Pool {
  auto get() -> std::unique_ptr<Interface>;
  std::vector<std::unique_ptr<Interface>> m_objects;
  Pool &m_pool;
};

My question is if it is possible to have the Implementation, instantiated as a pointer to Interface, move itself into the pool when its destructor is called?

Aucun commentaire:

Enregistrer un commentaire