C ++ array with semantics of values ​​and without manipulator-distributor?

I am looking for a C ++ container that intersects between boost :: array, boost :: scoped_array and std :: vector.

I need an array dynamically allocated via new [] (without custom allocators) contained in a type that has a meaningful copy constructor.

boost :: array has a fixed size, and although I do not need to resize, I do not know the size of the array at compile time.

boost :: scoped_array does not have a copy constructor, which means that I need to manually add one to each class using std :: copy (my previous copy-paste application). This is also error prone, as you better make sure that when you add the field to which you added the correct initializer to the custom copy constructor; that is, template loads.

std :: vector uses some pre-allocation system and therefore does not use the new [] operator. This is problematic because it requires specialized dispensers, and, even worse, even this is not enough, as there are some odd corner cases (which I don’t quite understand) in which there are semantics of returning to the value causing problems; I don’t want the container to do anything unusual, but just contain a new array [] 'd and copy it in its copy constructor - and preferably overload all the usual suspects that could be used as a collection.

, . , scoped_array, - (, std:: copy), . - ?

, .

+3
2

std::vector, . , resize() , , setsize() bool, , .

std::vector .

+1

. - ?

template <typename T> my_array {
    T* m_ptr;
    size_t m_size;
public:
    my_array(size_t sz)
        : m_ptr(new T[sz])
        , m_size(sz)
    {}
    my_array(const my_array &other)
        : m_ptr(new T[other.m_size])
        , m_size(other.m_size)
    {
        std::copy(other.m_ptr, other.m_ptr + other.m_size, m_ptr);
    }
    ~my_array() {
        delete[] m_ptr;
    }

    // ... operator[], etc.
};

- , - .

+1

Source: https://habr.com/ru/post/1721993/