Skip to content

Commit e34295a

Browse files
committed
Updated readme
1 parent 3cf2db6 commit e34295a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Built and tested on:
1313

1414
- [Introduction](#introduction)
1515
- [Usage](#usage)
16+
- [enable_observer_from_this](#enable_observer_from_this)
1617
- [Limitations](#limitations)
1718
- [Comparison spreadsheet](#comparison-spreadsheet)
1819
- [Speed benchmarks](#speed-benchmarks)
@@ -83,7 +84,14 @@ int main() {
8384
}
8485
```
8586

86-
As with `std::shared_ptr`/`std::weak_ptr`, if you need to obtain an observer pointer to an object when you only have `this` (i.e., from a member function), you can inherit from `oup::enable_observer_from_this<T>` to gain access to the `observer_from_this()` member function. This function will return a valid observer pointer as long as the object is owned by a unique or sealed pointer, and will return `nullptr` in all other cases. Contrary to `std::enable_shared_from_this<T>`, this feature naturally supports multiple inheritance.
87+
88+
## enable_observer_from_this
89+
90+
As with `std::shared_ptr`/`std::weak_ptr`, if you need to obtain an observer pointer to an object when you only have `this` (i.e., from a member function), you can inherit from `oup::enable_observer_from_this_unique<T>` or `oup::enable_observer_from_this_sealed<T>` (depending on the type of the owner pointer) to gain access to the `observer_from_this()` member function. Contrary to `std::enable_shared_from_this<T>`, this function is able to return a valid observer pointer at all times, even if the object is being constructed or is not owned by a unique or sealed pointer. Also contrary to `std::enable_shared_from_this<T>`, this feature naturally supports multiple inheritance.
91+
92+
To achieve this, the price to pay is that `oup::enable_observer_from_this_unique<T>` uses virtual inheritance, while `oup::enable_observer_from_this_sealed<T>` requires `T`'s constructor to take a control block as input (thereby preventing `T` from being default-constructible, copiable, or movable).
93+
94+
If these trade-offs are not appropriate for your use cases, they can be fine-tuned using the generic classes `basic_observable_pointer<T,Deleter,Policy>`, `basic_observer_ptr<T,Policy>`, and `basic_enable_observer_from_this<T,Policy>`. Please see the documentation for more information on policies.
8795

8896

8997
## Limitations
@@ -152,6 +160,8 @@ Detail of the benchmarks:
152160
- Create observer copy: construct a new observer pointer from another observer pointer.
153161
- Dereference observer: get a reference to the underlying object from an observer pointer.
154162

163+
The benchmarks were last ran for v0.4.0.
164+
155165
*Compiler: gcc 9.3.0, std: libstdc++, OS: linux 5.1.0, CPU: Ryzen 5 2600:*
156166

157167
| Pointer | raw/unique | weak/shared | observer/obs_unique | observer/obs_sealed |

0 commit comments

Comments
 (0)