Q
Q
Quad_Tree2019-02-21 12:20:39
C++ / C#
Quad_Tree, 2019-02-21 12:20:39

Do I need to use allocator::construct()?

In Björne Stroustrup's book, object initialization only goes through construct(). In the case of copying, the code looks like this:

for (int i=0; i<sz; ++i) alloc.construct(&p[i], elem[i]);

But if you use std::copy, then everything will work exactly the same:
std::copy(elem, elem+sz, p);
Is it necessary to use allocator::construct() to initialize an object?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman, 2019-02-21
@Quad_Tree

Depending on what you want to do.
yeah, only there will be memcpy or memove inside.

L
laphroaig, 2019-02-21
@laphroaig

If you are using an allocator to allocate memory, then there is no point in not using it for initialization. Another question is whether it makes sense to use it at all. If you do not quite understand why you need an allocator, then most likely you do not need it at all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question