4 ms·
Am I the only one who has never needed to do variadic anything? (minus something like flags) I'm really not sure what type of problem variadics solve that can'
by Night_Thastus 3y ago
Am I the only one who has never needed to do variadic anything? (minus something like flags)
I'm really not sure what type of problem variadics solve that can't be done simpler with something else, like default arguments, std::optional, containers like vector, etc.
- spacechild1 3y agoBut you have certainly been using variadic functions or classes, e.g. everytime you call std::make_unique(). Someone needs to write those :)
- Night_Thastus 3y agoThat's a fair point. It wasn't a criticism of the feature - more confusion about what exactly it's supposed to be good at solving. I'm never clear if I should be reaching for it. make_unique() is a good example.
- logicchains 3y agoYou can't do type-checked multi-dimensional containers like tensors without variadics. You could only manually create Tensor1D, Tensor2D, Tensor3D... types. You also couldn't implement tuple types without them.
- gpderetta 3y agoJust as a simple example, Optional and containers can use variadics to forward arguments to emplace-construct their contained objects. If you do not need variadics that's fine, you do not have to force them where they don't belong.
- Georgelemental 3y agoVariadics are rarely useful, but when you need them (generally in highly generic library code) you really need them. (I don't know C++, but am familiar with the pain of not having variadics in Rust, and the piles of macros required to work around it)