fork download
#include 
#include 

template 
class myqueue {
public:
    myqueue() : q() {}
    virtual ~myqueue() {}

    // pushes a copy
    void push(const T& item) {
        q.push(item);
    }
    // pushes the object itself (move)
    void push(T&& item) {
        q.push(std::move(item));
    }
private:
    std::queue q;
};

class nocopy {
public:
    // Default constructor
    nocopy() {}

    // Move semantics
    nocopy(nocopy&& other) {}
    nocopy& operator=(nocopy&& rhs) {
        nocopy(std::move(rhs)).swap(*this);
        return *this;
    }

    // Disable copy semantics
    nocopy(const nocopy& other) = delete;
    nocopy& operator=(const nocopy& rhs) = delete;

    void swap(const nocopy& other) {}
};

int main() {
    myqueue q1; // compiles fine.
    q1.push(1);

    std::queue q2; // compiles fine.
    nocopy nc1;
    q2.push(std::move(nc1));

    myqueue q3; // ERROR :(
    nocopy nc2;
    q3.push(std::move(nc2));
}


Success #stdin #stdout 0s 3028KB
stdin
Standard input is empty
stdout

Standard output is empty