3 ms·
> But even more than that, references that don't extend the lifetimes of objects (like native pointers and references) are simple to create and are in many ways
by cbsmith 10y ago
> But even more than that, references that don't extend the lifetimes of objects (like native pointers and references) are simple to create and are in many ways the default type of reference in C++.
C++ has a lot of cases of defaults that one tends not to use all that much (because it tends to default to maximal efficiency). Raw pointers would be a good example. Those are generally frowned upon.
On the other hand, references are encouraged and have pretty clear semantics around ownership.
> At any rate, 'this message queue only works with types that are easy to copy' is not generally a prominent part of the documentation in C++, if it's present at all.
Really? That's a very prominent part of say... the STL's documentation.
- humanrebar 10y agoEven the documentation of vector describes what it does and few implications. It doesn't warn you that vectors of raw pointers are bad parameter types, for example. It does talk about iterator invalidation, but it doesn't really educate us about how that affects our designs. That's not to criticize vector, but to point out that C++ had especially nuanced implications if loosely coupled design is a concern.
- cbsmith 10y ago> It doesn't warn you that vectors of raw pointers are bad parameter types, for example. Vectors of raw pointers function very effectively, they just have all the problems intrinsic with the use of raw pointers. I'm not sure I'd blame the vector documentation for that... > It does talk about iterator invalidation, but it doesn't really educate us about how that affects our designs. Design implications are a subtle thing that you can write entire books about. I think failing to fully capture those implications in the API documentation is more than understandable and far from unusual. For example, Java's containers have similar issues with iterator invalidation, and similarly don't have documentation on all the design implications.