Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Is there any interest for `std::unique_ptr` analogue with weak-semantic?

オープン
#119 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
cpp
領域
devtools

調査の方向性

リンクされた weakable_unique_ptr.hpp のプロトタイプと、Boost.SmartPtr ライブラリの規約を確認することから始めます。weakable_unique_ptr と unique_weak_ptr が Boost に適合するか、それらをどこに配置すべきか、列挙された制限のうちどれに対処する必要があるかを判断してください。完了とみなすには、合意された設計、Boost スタイルの実装、網羅的なテスト、ドキュメントが必要です。

索引モデルが issue の本文から書いたものです。

説明

Hi everyone,

I’ve implemented a weak-reference-enabled version of std::unique_ptr, called weakable_unique_ptr. The core idea is to combine the strict ownership semantics of std::unique_ptr with the ability to create non-owning observers (called unique_weak_ptr), without introducing shared ownership or thread-safety overhead.

Key Properties

  • Exclusive Ownership: The owned object is destroyed when the weakable_unique_ptr is destroyed (like std::unique_ptr);
  • Observation: unique_weak_ptr observers automatically expire when the owned object is destroyed (like std::weak_ptr);
  • Less cost: no copy operation for weakable_unique_ptr at all, unique_weak_ptr's reference counter without atomic operations.

Implementation Status
Attached is a working prototype of weakable_unique_ptr and unique_weak_ptr, tested on Godbolt's GCC 15.1.
The current implementation is standalone (no modifications to Boost.SmartPtr library required) and supports:

  • Move-only semantics (like std::unique_ptr);
  • Safe validity checks via try_get() or expired().

The current implementation doesn't support yet:

  • Handling array types;
  • Handling deleter as reference;
  • EBO for deleter;
  • Lazy initalization for control block(BTW do we really need to support it?);
  • Type erasing for control block(in order not to pollute binary);
  • Construction and assignment from std::unique_ptr;
  • operator[] for array types;
  • implicit conversion to std::shared_ptr.

Use Case Example

struct Node { 
    boost::weakable_unique_ptr<Node> child; 
    boost::unique_weak_ptr<Node> parent; // Safe back-reference 
}; 

void demo() { 
    auto root = boost::make_weakable_unique<Node>(); 
    auto child = boost::make_weakable_unique<Node>(); 
    child->parent = root; // Safe link 
    root->child = std::move(child); 
} // All auto-destructs, no leaks 

This is useful for:

  • Trees/ASTs with parent links.
  • GUI hierarchies (e.g., widgets owning children but needing parent access).
  • Any graph structure where ownership is linear but observation is needed.

Next Steps
If there’s interest, I’d love to:

  1. Polish the code to Boost standards.
  2. Add exhaustive tests/docs.
  3. Integrate with Boost.SmartPtr library.

Questions for the community:

  • Does this align with Boost’s goals?
  • Should it live under Boost.SmartPtr library or as a standalone utility?
  • Any design concerns?

weakable_unique_ptr
The full snippet to play: https://godbolt.org/z/41535cTvo

主要言語
C++
スター
111
フォーク
116
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

boostorg/smart_ptr のほかの issue

boostorg/smart_ptr の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。