ericniebler / range-v3

Range library for C++14/17/20, basis for C++20's std::ranges
Other
4.14k stars 439 forks source link

basic_view prevents EBO #1416

Open JohelEGP opened 4 years ago

JohelEGP commented 4 years ago

In strong typing a range-v3 view, I found its sizeof to not match my expectations. It turns out that both the strong type and its wrapped, sole data member view both inherit from basic_view<unknown>, which means that EBO can't kick in. Seems like I'll have to inherit from it rather than compose it and inherit from view_interface (which is how it also inherits from basic_view<unknown>).

Demonstration: https://godbolt.org/z/7ruD3C.

#include <string_view>
#include <range/v3/view/take.hpp>
#include <range/v3/view/interface.hpp>

using X = decltype(ranges::views::take(std::string_view{}, 42));

struct Y : ranges::cpp20::view_interface<Y>
{
    X base;
};

static_assert(sizeof(X) != sizeof(Y));
JohelEGP commented 3 years ago

See also the "UPDATE, 2021-05-08:" at https://quuxplusone.github.io/blog/2021/05/07/std-iterator-as-a-base-class/.