Constructor move not called when using boost :: pool_allocator

I have the following simple test code.

#include <stack>
#include <iostream>
#include "boost/pool/pool_alloc.hpp"

struct Frame
{
    uint32_t i{};

    Frame(uint32_t _i) : i(_i) {}

    Frame(const Frame& f)
    {
        std::cout << "Copy constructor" << std::endl;
        i = f.i;
    }

    Frame(Frame&& f)
    {
        std::cout << "Move constructor" << std::endl;
        std::swap(i, f.i);
    }
};

int main(int argc, char* argv[])
{
    {
        std::stack<Frame, std::deque<Frame>> stack;

        Frame f(0);
        stack.push(std::move(f)); // Move constructor
        stack.push(Frame(1)); // Move constructor
    }

    {
        std::stack<Frame, std::deque<Frame, boost::pool_allocator<Frame>>> stack;

        Frame f(0);
        stack.push(std::move(f)); // Copy constructor
        stack.push(Frame(1)); // Copy constructor
    }


    return 0;
}

      

When I compile this code using Clang or GCC, it gives me the following output:

Move constructor
Move constructor
Copy constructor
Copy constructor

      

Why boost::pool_allocator

does using prevent the compiler from using the move constructor?
Did I miss something?

+3


source to share


1 answer


pool_allocator

does not rebuild the arguments construct

: it just takes a reference const

to the value type and passes that value as an initializer for placement new

.



This is because it pool_allocator

has not yet been updated for C ++ 11.

+5


source







All Articles