小编Mat*_*llo的帖子

使用boost :: pool_allocator时不调用Move构造函数

我有以下简单的测试代码.

#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 …
Run Code Online (Sandbox Code Playgroud)

c++ boost move-semantics boost-pool c++11

3
推荐指数
1
解决办法
216
查看次数

标签 统计

boost ×1

boost-pool ×1

c++ ×1

c++11 ×1

move-semantics ×1