logoalt Hacker News

cherryteastaintoday at 2:04 PM0 repliesview on HN

In C++ you'd just do

    template <typename T>
    void DoSomething(T const& data);
or if T* is supposed to point to a tightly packed buffer

    template <typename T>
    void DoSomething(std::span<T> data);
as the author pointed out. I don't see how that is ugly or more complicated than the original void* approach.

There is no need to pass the size of T or length of the span, former is just a sizeof(T) away and latter is a data.size(); away.

In fact, a lot of codebases would outright ban the uint8_t* and reinterpret_cast trick the author is complaining about via clang-tidy rules.