noncopyable

C++ container with non-copyable non-movable element type

坚强是说给别人听的谎言 提交于 2019-12-12 12:08:41
问题 I need a container of elements that are neither copyable nor movable. These elements are not default constructible, but their constructors get identical arguments. The size of the container does not change during it's lifetime. It should be as simple as a built-in array, but it's size is determined at run-time when the constructor is called. Is there an easy way to implement that without the overhead of memory allocation and indirection incurred by using std::vector<std::unique_ptr<T>> ? 回答1:

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

ぐ巨炮叔叔 提交于 2019-12-12 04:58:48
问题 #include <memory> #include <unordered_map> #include <vector> #include <utility> #include <boost/ptr_container/ptr_deque.hpp> struct T { T() = default; T(T const &) = delete; T & operator = (T const &) = delete; T(T &&) = default; T & operator = (T &&) = default; }; using S = boost::ptr_deque < T >; int main() { std::unordered_map < uint32_t, S > testum; // testum.emplace(1u, S()); // testum.insert(std::make_pair(1u, S())); testum[1].push_back(new T()); } In the above example, the commented

Initialize static std::map with non copyable value in a uniformed inline initialization

时光总嘲笑我的痴心妄想 提交于 2019-12-09 17:07:03
问题 I'd like to initialize a static std::map where the value is not copyable. I'll call my class ValueClass . ValueClass has an std::unique_ptr as private member and I even ensure that ValueClass is not copyable by extending non_copyable that looks like the following: class non_copyable { public: non_copyable() = default; protected: virtual ~non_copyable() = default; private: non_copyable(const non_copyable&) = delete; non_copyable& operator=(const non_copyable&) = delete; }; Now I'm trying to

c# select text from messagebox.show popup

你离开我真会死。 提交于 2019-12-09 14:23:28
问题 i've been searching on google and stackoverflow for 2hours now. There has to be something i am just simply overlooking. Is there an easy way to make the text selectable in a messagebox? As of right now when i call a MessageBox.Show() i can not copy the text displayed. Why not? how would i set the text to be copy able? my code: //catch all exceptions catch (Exception ex) { MessageBox.Show(ex.Message); //throw; } I want to be able to select the error message that comes out so a user can send it

How to deal with noncopyable objects when inserting to containers in C++

巧了我就是萌 提交于 2019-12-09 08:51:00
问题 I'm looking for the best-practice of dealing with non-copyable objects. I have a mutex class, that obviously should not be copyable. I added a private copy constructor to enforce that. That broke the code - some places simply needed to be fixed, but I have a generic problem where a class, using the mutex either as a data member, or by inheritance, is being inserted into a container. This is usually happening during the container initialization, so the mutex is not initialized yet, and is

init boost::optional of non-copyable object

淺唱寂寞╮ 提交于 2019-12-06 19:22:53
问题 What should I do to initialize boost::optional< T > if underlying type T is non-default constructible, non-copyable/moveable, but one's instance still can exist? Is it forbidden for boost::optional by any semantic reasons to have some member function like template< typename... Args > boost::optional< T >::construct(Args && ...args) , that delivers all the arguments to in-place operator new to construct the object entirely (for non-ref type T )? Variant is to have non-member function like std:

Implementation supplied copy constructor and assignment operator

∥☆過路亽.° 提交于 2019-12-06 08:42:55
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 we derive from a class which has a private copy ctor and/or copy assignment operator. I am a little confused about the second situation, is the second situation is precisely. a) The implementation will not declare them for you, so you will get a compile time error. OR b) The implementation will declare and define them, but when the compiler defined

init boost::optional of non-copyable object

浪尽此生 提交于 2019-12-05 02:04:01
What should I do to initialize boost::optional< T > if underlying type T is non-default constructible, non-copyable/moveable, but one's instance still can exist? Is it forbidden for boost::optional by any semantic reasons to have some member function like template< typename... Args > boost::optional< T >::construct(Args && ...args) , that delivers all the arguments to in-place operator new to construct the object entirely (for non-ref type T )? Variant is to have non-member function like std::make_shared< T > . It seems to me, that my problem can be solved by means of using of std::unique_ptr

Initialize static std::map with non copyable value in a uniformed inline initialization

荒凉一梦 提交于 2019-12-04 04:38:38
I'd like to initialize a static std::map where the value is not copyable. I'll call my class ValueClass . ValueClass has an std::unique_ptr as private member and I even ensure that ValueClass is not copyable by extending non_copyable that looks like the following: class non_copyable { public: non_copyable() = default; protected: virtual ~non_copyable() = default; private: non_copyable(const non_copyable&) = delete; non_copyable& operator=(const non_copyable&) = delete; }; Now I'm trying to define a std::map using my class as value: static std::map<int, ValueClass> value_classes = { {0,

How to deal with noncopyable objects when inserting to containers in C++

你。 提交于 2019-12-03 12:16:07
I'm looking for the best-practice of dealing with non-copyable objects. I have a mutex class, that obviously should not be copyable. I added a private copy constructor to enforce that. That broke the code - some places simply needed to be fixed, but I have a generic problem where a class, using the mutex either as a data member, or by inheritance, is being inserted into a container. This is usually happening during the container initialization, so the mutex is not initialized yet, and is therefore ok, but without a copy constructor it does not work. Changing the containers to contain pointers