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
1
vote
2 answers

Prevent assignment of a type in C

Given a C function: void f(T x, T y) { x = y; } I want to make sure that all instances of T assignments will fail. So far, the best solution I have is something like: #define T const void * is there a better solution? (Ideally I would like T…
tohava
  • 5,344
  • 1
  • 25
  • 47
1
vote
1 answer

noncopyable static const member class in template class

I have a non-copyable (inherited from boost::noncopyable) class that I use as a custom namespace. Also, I have another class, that uses previous one, as shown here: #include #include template< typename F > struct…
Tomilov Anatoliy
  • 15,657
  • 10
  • 64
  • 169
1
vote
2 answers

make_pair like trick for noncopyable classes

make_pair can create pairs without mentioning the types. I want to use the same trick for my class, but it inherits from boost::noncopyable, so this does not compile: template struct bit_writer : boost:noncopyable { Iter iter; …
Bruno Martinez
  • 2,850
  • 2
  • 39
  • 47
0
votes
2 answers

How to stop users from copying or printing text from my web page?

I have a web page (on .Net platform, with C#) with text content and I would like to block users from copying the text or printing the document. If the user is hard out on attaining a copy of the page, I know he can. But I would like to make it as…
Null Head
  • 2,877
  • 13
  • 61
  • 83
0
votes
0 answers

Customized error message for deleted function use

Let's say I have a noncopyable class and I want to provide a customized error message when users try to copy. struct A { A() = default; private: [[deprecated("customized message")]] A(const A&); [[deprecated("customized…
0
votes
1 answer

Replace const std::string passed by reference, with std::string_view

I've got the following method which gets std::string as input argument. int func(const std::string &filename); From it's signature, the input type refers passed by reference (no copy is made) and shouldn't be changed (by the const prefix). Would it…
Zohar81
  • 4,554
  • 5
  • 29
  • 82
0
votes
1 answer

Error setting up unordered_map with non copying-able type with gcc 8.4

See here: https://godbolt.org/z/MW3jW6 Using gcc 8.4 (8.3 in godbolt) my code is failing to compile. With gcc 10.x it seems to compile ok. But I can't figure out what the error is telling me exactly... Here is the code for reference: #include…
code_fodder
  • 15,263
  • 17
  • 90
  • 167
0
votes
1 answer

std::optional taking non-copyable?

Suppose i have something akin to this pseudocode: std::optional > > getDataTogetherWithLock() { if (!some_ptr) { return std::nullopt; } return some_ptr->getDataTogetherWithLock();//just…
darune
  • 10,480
  • 2
  • 24
  • 62
0
votes
0 answers

What are the limitations of using boost mapped_matrix with std::unique_ptr?

Are there any limitations using boost's mapped_matrix with non-copyable objects like std::unique_ptr? I'm on VS2017 in C++14 mode. #include #include "boost/numeric/ublas/matrix_sparse.hpp" class myClass { public: myClass() {} …
Don Pedro
  • 335
  • 3
  • 7
0
votes
1 answer

Difference between std::unordered_map < K, boost::ptr_deque < T > >'s operator[] (K const &) and emplace

#include #include #include #include #include struct T { T() = default; T(T const &) = delete; T & operator = (T const &) = delete; T(T &&) = default; …
zrb
  • 851
  • 7
  • 16
0
votes
1 answer

SFML Input system problem

So I was porting my game engine from SDL to SFML, and now I have a problem with my input system. Input.h #ifndef BULLWHIP_INPUT_H #define BULLWHIP_INPUT_H #include class bc_Input { public: bool bm_KeyHit(sf::Key::Code key); …
Chris
  • 515
  • 1
  • 6
  • 16
0
votes
1 answer

`noncopyable` with custom destructor

I need a noncopyable class which has a declared destructor, and naive approach doesn't work: see https://ideone.com/mU8aoc. What's the problem with the destructor, why moving doesn't work the same way as without it? And of course, how to fix it? For…
aplavin
  • 2,199
  • 5
  • 32
  • 53
0
votes
1 answer

Macro to make class noncopyable

Is there any problem with following macro that makes a class non-copyable? #define PREVENT_COPY(class_name) \ class_name(const class_name&) = delete;\ class_name& operator=(const class_name&) = delete; class Foo { public: PREVENT_COPY(Foo) …
quantum_well
  • 869
  • 1
  • 9
  • 17
0
votes
2 answers

C++ how noncopyable works?

How inheriting a noncopyable class with a private copy constructor and an assignment operator is going to prohibit the use of copy constructor and assignment operator on the derived class? Please consider the following scenario while replying,…
0
votes
1 answer

What is the best syntax to declare a class as noncopyable?

(assuming I cannot use boost::noncopyable, which was explicitly designed for that purpose) (assuming I cannot use C++11) When making a class noncopyable, I usually see the following syntax: class MyClass { public: ... stuff …
anatolyg
  • 26,506
  • 9
  • 60
  • 134