Skip to content

Ownership & move-only Graph #225

@allnes

Description

@allnes

Please make Graph move-only and avoid sharing node ownership. Copying a graph is ambiguous and expensive; move-only makes lifetime explicit and prevents accidental deep/shallow copies. Also, keep a single owner of layers inside Graph and pass raw pointers (or ids) for wiring to avoid refcount overhead on the hot path.

// graph.hpp
class Graph {
public:
  Graph(const Graph&) = delete;
  Graph& operator=(const Graph&) = delete;
  Graph(Graph&&) noexcept = default;
  Graph& operator=(Graph&&) noexcept = default;
  ~Graph() = default;
  // ...
};

// preferred API inside Graph
Layer* addLayer(std::unique_ptr<Layer> L); // returns non-owning handle for connections

It's avoids atomic refcount churn from shared_ptr, eliminates hidden cycles, and makes lifetime rules crystal clear.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions