Questions tagged [noncopyable]

The boost::noncopyable class is used as a base class to make a C++ type unable to be copied or assigned. This tag is for the boost library utility noncopyable.

The boost::noncopyable class is used as a base class (usually private) to make a C++ type unable to be copied or assigned.

It is intended to be used as a private base. boost::noncopyable has private (under C++03) or deleted (under C++11) copy constructor and a copy assignment operator and can't be copied or assigned; a class that derives from it inherits these properties.

Use this tag is for the boost library utility noncopyable.

76 questions
4
votes
1 answer

Storing non copyable object with no default constructor in map (C++11)

I'm trying to implement a class that represents a connection to a file, hence it should be a non-copyable class. Also, since a filename is required to create the object, I'd like to remove the default constructor. Here is a simplified definition of…
alcinos
  • 43
  • 4
3
votes
1 answer

Creating a Noncopyable class and inherit into my class

I am trying to create a non-copyable class and inherit it to myclass. Here's how the code looks: template struct NonCopyable { protected: NonCopyable() {} private: NonCopyable(const NonCopyable& x) = delete; T& operator=(const…
jan
  • 137
  • 2
  • 6
3
votes
2 answers

How to determine the type of a lambda which captures a noncopyable parameter?

Given the non copyable Task class and sample code below #include #include #include class Task { public: Task() { } Task(const Task& other) = delete; Task& operator=(const Task& other) =…
dgmz
  • 394
  • 3
  • 16
3
votes
6 answers

How to make a copyable boost::signal?

I get why boost::signal is noncopyable (it's because copying a signal doesn't have a clear meaning), but I need a version of it that does provide some sort of copy ctor (either a no-op or one that copies all connections). The reason I need this is…
Iraimbilanja
3
votes
1 answer

How to create a vector with non-copyable and non-assignable objects?

I have a class class A { public: A(int x): x_(x) {} void SetValue(int m) {x_=m}; private: DISALLOW_COPY_AND_ASSIGN(A); }; I'm trying to create a vector of objects of type A vector> objects; objects.reserve(10); for (int…
user1159517
  • 5,390
  • 8
  • 30
  • 47
3
votes
2 answers

What are use cases for booster::noncopyable?

First: is it boost::noncopyable or booster::noncopyable. I have seen both in different places. Why would one want to make a class noncopyable? Can you give some sample use cases?
augustin
  • 14,373
  • 13
  • 66
  • 79
3
votes
1 answer

Is there any way to static_assert that template argument is noncopyable?

Is there any way to determine that some type is non-copyable during compile time? I need following: template struct circular_buffer : boost::noncopyable { static_assert(typeof(T) ?????, "T must be…
nothrow
  • 15,882
  • 9
  • 57
  • 104
3
votes
1 answer

Error: "cannot access private member declared in class 'boost::signals2::scoped_connection'"?

class Whatever { public: virtual ~Whatever(); protected: Whatever(); virtual void SomeMethod(); void OnEventOccurred(int x); std::vector boostSignalConnections_; } //…
User
  • 62,498
  • 72
  • 186
  • 247
2
votes
2 answers

Standard layout and non-copyable property

C++11, §9/7: A standard-layout class is a class that: has no non-static data members of type non-standard-layout class (or array of such types) or reference, has no virtual functions and no virtual base classes, has the same access control for all…
BЈовић
  • 62,405
  • 41
  • 173
  • 273
2
votes
2 answers

move semantics unused in presence of std::move

With the following: #include #include using namespace std; int main() { ifstream f; ifstream g; f = std::move(g); } Why is ifstream::operator=(const ifstream&) being called instead of ifstream::operator=(ifstream&&)…
moshbear
  • 3,282
  • 1
  • 19
  • 33
2
votes
2 answers

inheriting noncopyable has no effect in dllexport classes

UPDATE the belowmentioned bug is fixed in VS2012, and noncopyable works as epected This is both a question and a way to provide information / warn others so they don't fall into the same trap as I did: it seems that using a noncopyable base class…
stijn
  • 34,664
  • 13
  • 111
  • 163
2
votes
1 answer

Copy/move elision with a check

Consider this. There is a non-copyable, non-movable class, and there is some predicated defined for it: struct AA { AA(AA const& otehr) = delete; AA(AA && otehr) = delete; AA& operator = (AA const& otehr) = delete; AA&…
Vahagn
  • 4,670
  • 9
  • 43
  • 72
2
votes
6 answers

Implementation supplied copy constructor and assignment operator

I have a small confusion regarding the situations where the implementation (compiler) will not supply the copy constructor and the copy assignment operator. When we declare the copy ctor and/or copy assignment operator in our class. Some says when…
riderchap
  • 667
  • 2
  • 11
  • 19
2
votes
0 answers

Any disadvantage of inheriting from boost::noncopyable vs delete copy ctor and op?

First: class T1 : boost::noncopyable { // ... } Second: class T2 { public: T2(const T2&) = delete; T2& operator=(const T2&) = delete; } Are they the same? What are disadvantages of each? I mean runtime costs, not comfort of writing…
vladon
  • 8,158
  • 2
  • 47
  • 91
2
votes
3 answers

Is it possible to make an noncopyable type in C#

Is it somehow possible in C# to create a class that can not be copied around but rather can only be passed around by reference? The equivalent in C++ would be to delete the copy-constructor and the copy-assignment operator.
Knitschi
  • 2,822
  • 3
  • 32
  • 51