containers

QList of QScopedPointers

▼魔方 西西 提交于 2019-12-20 02:42:06
问题 I'm trying to store QScopedPointers in a QList. I found this comment One can also use QList >. – Kuba Ober Jan 14 '14 at 18:17 (first comment on this answer: https://stackoverflow.com/a/21120575/3095014) and this post https://forum.qt.io/topic/59338/solved-qlist-of-qscopedpointers which implies that this should work. But if I try to compile the code of the second link, I'm getting this errors: E:\Qt\Qt5Enterprise\5.5\msvc2013\include\QtCore/qlist.h(404) : error C2248: 'QScopedPointer<Label

Why C++ associative containers predicate not transparent by default?

僤鯓⒐⒋嵵緔 提交于 2019-12-20 02:30:10
问题 Since C++14 we have std::less<void> that is transparent and more usefull in most cases, so is there reasons why, for example, std::set still has std::less<Key> as a predicate by default, not an std::less<void> except historical reasons. Useful cases: std::set<std::string>::find with std::string_view , etc. 回答1: It would break current working code to do so. Imagine I have struct my_type { int id; int bar; }; namespace std { template<> struct less<my_type> { bool operator()(my_type const& lhs,

Why C++ associative containers predicate not transparent by default?

旧时模样 提交于 2019-12-20 02:30:03
问题 Since C++14 we have std::less<void> that is transparent and more usefull in most cases, so is there reasons why, for example, std::set still has std::less<Key> as a predicate by default, not an std::less<void> except historical reasons. Useful cases: std::set<std::string>::find with std::string_view , etc. 回答1: It would break current working code to do so. Imagine I have struct my_type { int id; int bar; }; namespace std { template<> struct less<my_type> { bool operator()(my_type const& lhs,

C++ Is a std::string a container?

南笙酒味 提交于 2019-12-19 18:47:33
问题 This might be a simple question for some of you. But I was wondering if a std::string is a container. By container I mean the containers like for example std::vector , std::list and std::deque . Since std::basic_string<> accepts other types than integral characters, but also is being optimized by working with character arrays. It isn't really clear to me in which category it falls. This will compile: #include <string> #include <iostream> int main() { std::basic_string<int> int_str; int_str

How to implement a simple container with placement new and emplace functionality?

元气小坏坏 提交于 2019-12-19 08:08:09
问题 I need to implement a container to hold an amount of elements and for some reason, it has to work without any heap allocation. Another requirement is, that the container elements should not be copied or moved in any way. They have to constructed directly into the memory allocated by the container. For that, I decided to use placement new and delegate the memory management completely to the container implementation (found some useful information about placement new at drdobbs). A running

is std::queue thread safe with producer and multiple consumers

萝らか妹 提交于 2019-12-19 05:15:30
问题 how can I make a queue thread safe? I need to push / pop / front / back and clear. is there something similar in boost? I have one producer and one or more consumer. 回答1: You must protect access to std::queue . If you are using boost protect it using boost::mutex . Now if you have multiple readers and one writer thread look at boost::shared_lock (for readers) and boost::unique_lock (for writer). However if you will encounter writer thread starvation look at boost::shared_mutex . 回答2: std:

limit size of Queue<T> in C++

人走茶凉 提交于 2019-12-19 05:06:58
问题 I notice the thread of similar question: Limit size of Queue<T> in .NET? That's exactly what I want to do, but I am not using .net but GNU C++. I have no reference to the base class in GNU C++, so java like super.***() or .net like base.***() will not work. I have been trying to inherit from queue class but it turns out in vain. What I want to do: specify the size of the queue, and automatically dequeue when the queue is full. To be specific: if the maximum size of my queue is 2, when I push

“CopyConstructible” requirement for C++ stl container element

独自空忆成欢 提交于 2019-12-19 00:55:10
问题 Regarding to the requirement for C++ stl container element, the standard says: the element type should be CopyConstructible, and there is a table for CopyConstructible requirements. Also by various books (Josuttis, etc.), the generated copy should be "equivalent to" the source. I think I need some clarity here. What is exactly "equivalent to"? Also I am a bit confused with the relation between the "CopyConstructible" and the "deep/shallow copy". In general, a copy constructor is either

Connect to host mongodb from docker container

本小妞迷上赌 提交于 2019-12-18 19:00:59
问题 So I want to connect to my mongodb running on my host machine (DO droplet, Ubuntu 16.04). It is running on the default 27017 port on localhost. I then use mup to deploy my Meteor app on my DO droplet, which is using docker to run my Meteor app inside a container. So far so good. A standard mongodb://... connection url is used to connect the app to the mongodb. Now I have the following problem: mongodb://...@localhost:27017... obviously does not work inside the docker container, as localhost

Connect to host mongodb from docker container

最后都变了- 提交于 2019-12-18 19:00:03
问题 So I want to connect to my mongodb running on my host machine (DO droplet, Ubuntu 16.04). It is running on the default 27017 port on localhost. I then use mup to deploy my Meteor app on my DO droplet, which is using docker to run my Meteor app inside a container. So far so good. A standard mongodb://... connection url is used to connect the app to the mongodb. Now I have the following problem: mongodb://...@localhost:27017... obviously does not work inside the docker container, as localhost