Date: Sun, 28 Jul 2024 22:19:45 +0800

Hi All,

Quoting the original paperâ€™s description

<https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p0843r14.html#Deduction-guides>

for deduction guides for std::inplace_vector: "*Unlike the other

containers, inplace_vector** does not have any deduction guides because

there is no case in which it would be possible to deduce the second

template argument, the capacity, from the initializer.*"

However, I found that in some cases it is possible to enable CTAD for

std::inplace_vector, for example when we accept a std::array or std::span:

template<class T, size_t N>

inplace_vector(from_range_t, const std::array<T, N>&) -> inplace_vector<T,

N>; // new CTAD

Then we can:

std::inplace_vector v{std::from_range, std::array{1, 2, 3}}; I think this

makes meta-programming more user-friendly and convenient, for example,

converting index_sequence into inplace_vector and then applying the

algorithm in <algorithm>:

constexpr inplace_vector v = []<size_t... Is>(index_sequence<Is...>) {

inplace_vector v{from_range, array{Is...}};

auto [begin, end] = ranges::remove(v, 42);

v.erase(begin, end);

return v;

}(std::make_index_sequence<N>{});

Would it be valuable for inplace_vector to introduce std::array or

std::span-specific

CTADs? Thanks, Hewill

Quoting the original paperâ€™s description

<https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p0843r14.html#Deduction-guides>

for deduction guides for std::inplace_vector: "*Unlike the other

containers, inplace_vector** does not have any deduction guides because

there is no case in which it would be possible to deduce the second

template argument, the capacity, from the initializer.*"

However, I found that in some cases it is possible to enable CTAD for

std::inplace_vector, for example when we accept a std::array or std::span:

template<class T, size_t N>

inplace_vector(from_range_t, const std::array<T, N>&) -> inplace_vector<T,

N>; // new CTAD

Then we can:

std::inplace_vector v{std::from_range, std::array{1, 2, 3}}; I think this

makes meta-programming more user-friendly and convenient, for example,

converting index_sequence into inplace_vector and then applying the

algorithm in <algorithm>:

constexpr inplace_vector v = []<size_t... Is>(index_sequence<Is...>) {

inplace_vector v{from_range, array{Is...}};

auto [begin, end] = ranges::remove(v, 42);

v.erase(begin, end);

return v;

}(std::make_index_sequence<N>{});

Would it be valuable for inplace_vector to introduce std::array or

std::span-specific

CTADs? Thanks, Hewill

Received on 2024-07-28 14:20:02