3 ms·
I'd rather have an optionally-owned pointer type so I can handle writing virtual methods that can return a value aliasing an already existing value or create a
by gct 3y ago
I'd rather have an optionally-owned pointer type so I can handle writing virtual methods that can return a value aliasing an already existing value or create a new one on demand. Otherwise you either have to roll your own or bloat your API:
virtual std::flexptr<Thing> get_expensive_thing();
vs:
virtual bool has_expensive_thing();
virtual const Thing& get_expensive_thing();
virtual std::unique_ptr<Thing> build_expensive_thing();
It'd probably have shared_ptr semantics but you'd have to treat it as a const ref for lifetime purposes, which might make it distasteful to the std library folks.