Код: Выделить всё
#include
#include
#include
#include
#include
#include
template
concept has_resize = requires(T t)
{
{t.resize(0)};
};
template
class Vec
{
C elems;
public:
template
requires std::integral && std::is_unsigned_v
auto operator[](IndexType i) const
{
return elems[i];
}
auto size() const { return elems.size(); }
template
Vec(std::initializer_list init)//MEMBER INITIALIZER LIST?
{
// WHAT CODE GOES HERE?
}
Vec(auto init)
{
if constexpr (has_resize)
elems.resize(init.size());
for (decltype(init.size()) i = 0; i Vec;
//WHAT'S THE CORRECT DEDUCTION GUIDE?
int main()
{
Vec v0({1, 4, 7});
Vec v1(std::array{2, 5, 8});
Vec v2(std::vector{3, 6, 9});
}
Подробнее здесь: https://stackoverflow.com/questions/784 ... -right-way