3 ms·
In C++, you can do much of what you want with std::array, std::mdspan... and you could also create a Ptr<T> with "using" to define a type alias for T* -- see [0
by Quekid5 2y ago
In C++, you can do much of what you want with std::array, std::mdspan... and you could also create a Ptr<T> with "using" to define a type alias for T* -- see [0]. Of course the default syntax for pointers is T* and that's not going to change, so it'll be an uphill battle to keep consistent in any codebase. (I guess systematic use of a rule in clang-tidy or such could help with that.)
[0] https://en.cppreference.com/w/cpp/language/type_alias https://en.cppreference.com/w/cpp/language/type_alias
- delta_p_delta_x 2y agoIndeed, and there's `std::function` (albeit not being a zero-cost abstraction; I believe `std::move_only_function` and `std::copyable_function` in C++23 and C++26 respectively are replacements) and lambda statements. But C++ decided the bracket salad `[](){}` was the best way to write lambdas, and I'll never forgive the standard for it.
- kccqzy 2y agoAny sort of type erasure on functions will have a non-zero cost. That's why the only zero-cost abstraction is having a template parameter (such as remove_if), but these come with a code size cost instead.