posts: generic-flyweight: fix lint issues
This commit is contained in:
parent
3b4756e8d8
commit
5b5a9bbd5d
|
@ -86,10 +86,12 @@ cannot keep the `vector` sorted to do binary searches and insertion, because
|
||||||
the flyweights rely on their index inside the vector being stable.
|
the flyweights rely on their index inside the vector being stable.
|
||||||
|
|
||||||
Instead, I'd recommend you use an `std::set` for the following reasons:
|
Instead, I'd recommend you use an `std::set` for the following reasons:
|
||||||
|
|
||||||
- its semantic implies an ordering relationship, without duplication
|
- its semantic implies an ordering relationship, without duplication
|
||||||
- it has an (asymptotically) efficient insertion.
|
- it has an (asymptotically) efficient insertion.
|
||||||
- it has stable iterators/pointers on insertion: a flyweight can just refer to
|
- it has stable iterators/pointers on insertion: a flyweight can just refer to
|
||||||
a pointer to the object contained inside the `std::set`.
|
a pointer to the object contained inside the `std::set`.
|
||||||
|
|
||||||
That last bullet point is the reason why I'd recommend using a `set` instead of
|
That last bullet point is the reason why I'd recommend using a `set` instead of
|
||||||
a sorted `vector`.
|
a sorted `vector`.
|
||||||
|
|
||||||
|
@ -110,13 +112,13 @@ public:
|
||||||
```
|
```
|
||||||
|
|
||||||
The little `&(*instances_.emplace(c))` does all the work for us:
|
The little `&(*instances_.emplace(c))` does all the work for us:
|
||||||
|
|
||||||
- `instances_.emplace(c)` creates the corresponding metadata only if it isn't in
|
- `instances_.emplace(c)` creates the corresponding metadata only if it isn't in
|
||||||
the set already.
|
the set already.
|
||||||
- We get an iterator back to the inserted element from this operation
|
- We get an iterator back to the inserted element from this operation
|
||||||
- We dereference it (`*<IT>`) to get a `GlyphMetadata&`
|
- We dereference it (`*<IT>`) to get a `GlyphMetadata&`
|
||||||
- We take the address of that reference for our flyweight (`&(<REF>)`).
|
- We take the address of that reference for our flyweight (`&(<REF>)`).
|
||||||
|
|
||||||
|
|
||||||
### Templating
|
### Templating
|
||||||
|
|
||||||
This scheme with an `std::set` is easily templatable: indeed we can imagine a
|
This scheme with an `std::set` is easily templatable: indeed we can imagine a
|
||||||
|
|
Loading…
Reference in a new issue