News for hackers. Stuff that matters.
Re:Modernize C++: Sink Functions by kllrnohj on Thursday December 07, 2017 @12:25PM (#15871911)
I'd argue that classes with a single field are a worse code smell. A using or typedef would be better, at least then your code isn't littered with unneeded field accesses.

I agree that these methods should just take rvalue references, though. Doesn't really matter for unique_ptr, but for other things like shared_ptr it adds up quick.

Re:Modernize C++: Sink Functions by smitherfield on Thursday December 07, 2017 @01:16PM (#15872509)
>I'd argue that classes with a single field are a worse code smell. A using or typedef would be better

Sometimes, but not in this case, because

- Smart pointers are nullable, which should be opt-in and not opt-out behavior.

- Smart pointers have pointer-like interfaces, which do not read like idiomatic modern C++. A wrapper class `GadgetHandle` can define conversion operators for `Gadget&` and `const Gadget&` so their interface reflects their semantic meaning (a `Gadget`) and hides irrelevant or unsafe implementation details (the operators and methods belonging to the smart pointer class).

- As a corollary to the above, you can create several classes `UniqueGadgetHandle`, `SharedGadgetHandle`, `CustomGadgetHandle` and so forth, which enable you to very easily and transparently intermix or alter allocation strategies (even on the stack or statically) for your `Gadget`s, usually without needing to alter any public APIs or more than one section of your codebase.

- When your heap-allocated data [structures] don't semantically correspond to the containers provided by the STL or your other library dependencies, I find that chances are you have or may add some custom constructor/destructor logic beyond just new and delete.

Re:Modernize C++: Sink Functions by Koshkin on Thursday December 07, 2017 @04:35PM (#15874527)
You cannot use a typedef if you intend to create a new type (e.g. one that provides a specific set of methods but otherwise identical to a built-in type).