containers

Emulating membership-test in Python: delegating __contains__ to contained-object correctly

南楼画角 提交于 2019-12-09 12:44:19
问题 I am used to that Python allows some neat tricks to delegate functionality to other objects. One example is delegation to contained objects. But it seams, that I don't have luck, when I want to delegate __contains __: class A(object): def __init__(self): self.mydict = {} self.__contains__ = self.mydict.__contains__ a = A() 1 in a I get: Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: argument of type 'A' is not iterable What I am making wrong? When I call a._

Get numeric index from Boost multi-index iterator

孤人 提交于 2019-12-09 12:26:13
问题 I'm storing a bunch of the following struct Article { std::string title; unsigned db_id; // id field in MediaWiki database dump }; in a Boost.MultiIndex container, defined as typedef boost::multi_index_container< Article, indexed_by< random_access<>, hashed_unique<tag<by_db_id>, member<Article, unsigned, &Article::db_id> >, hashed_unique<tag<by_title>, member<Article, std::string, &Article::title> > > > ArticleSet; Now I've got two iterators, one from index<by_title> and one from index<by_id>

How to stop running Container, if error response from daemon is: Cannot Kill Container […] permission denied?

耗尽温柔 提交于 2019-12-09 09:47:53
问题 Tough task: Everytime I try to stop or kill a running container, I get permission denied as an error response from Daemon. I just started learning how to use docker by using a Ubuntu18.04 VM. I was running a container for the first time. I was not able to stop it but at least it was running. Now, after I tried to run another image "furtuas/daisitory:image_available_first_ms", everything got worse. Two containers are running, I can't stop non of them. I tried to restart docker but the

Contaner for different functions?

泄露秘密 提交于 2019-12-09 09:12:02
问题 I'm trying to implement a container class for different functions where I can hold function pointers and use it to call those functions later. I'll try to discribe my problem more accurate. As example, I have 2 different test functions: int func1(int a, int b) { printf("func1 works! %i %i\n", a, b); return 0; } void func2(double a, double b) { printf("func2 works! %.2lf %.2lf\n", a, b); } and I also have array of variants, which holds function arguments: std::vector<boost::variant<int, double

Is Stephen Lavavej's Mallocator the same in C++11?

让人想犯罪 __ 提交于 2019-12-09 05:27:49
问题 8 years ago, Stephen Lavavej published this blog post containing a simple allocator implementation, named the "Mallocator". Since then we've transitioned to the era of C++11 (and soon C++17) ... does the new language features and rules affect the Mallocator at all, or is it still relevant as is? 回答1: STL himself has an answer to this question in his STL Features and Implementation techniques talk at CppCon 2014 (Starting at 26'30). The slides are on github. I merged the content of slides 28

What's the best way to sum the result of a member function for all elements in a container?

寵の児 提交于 2019-12-09 02:37:04
问题 Let's say I have the following object: struct Foo { int size() { return 2; } }; What's the best way (most maintainable, readable, etc.) to get the total size of all objects in a vector<Foo> ? I'll post my solution but I'm interested in better ideas. Update: So far we have: std::accumulate and a functor std::accumulate and a lambda expression plain ol' for-loop Are there any other workable solutions? Can you make something maintainable using boost::bind or std::bind1st/2nd ? 回答1: In addition

Mapping between stl C++ and C# containers

别说谁变了你拦得住时间么 提交于 2019-12-08 23:01:21
问题 Can someone point out a good mapping between the usual C++ STL containers such as vector, list, map, set, multimap... and the C# generic containers? I'm used to the former ones and somehow I've accustomed myself to express algorithms in terms of those containers. I'm having some hard time finding the C# equivalent to those. Thank you! 回答1: Here's a rough equivalence: Dictionary<K,V> <=> unordered_map<K,V> HashSet<T> <=> unordered_set<T> List<T> <=> vector<T> LinkedList<T> <=> list<T> The .NET

Can I cast an array of POD which has floats to float*?

一曲冷凌霜 提交于 2019-12-08 19:12:05
问题 Consider the following: #include <vector> using namespace std; struct Vec2 { float m_x; float m_y; }; vector<Vec2> myArray; int main() { myArray.resize(100); for (int i = 0; i < 100; ++i) { myArray[i].m_x = (float)(i); myArray[i].m_y = (float)(i); } float* raw; raw = reinterpret_cast<float*>(&(myArray[0])); } Is raw guaranteed to have 200 contiguous floats with the correct values? That is, does the standard guarantee this? EDIT : If the above is guaranteed, and if Vec2 has some functions (non

docker-compose: connection refused between containers, but service accessible from host

落爺英雄遲暮 提交于 2019-12-08 19:10:59
问题 TL;DR: How do I have to change my below docker-compose.yml in order to allow one container to use a service of another over a custom (non-standard) port? I have a pretty common setup: containers for a web app (Padrino [Ruby]), Postgres, Redis, and a queueing framework (Sidekiq). The web app comes with its custom Dockerfile, the remaining services come either from standard images (Postgres, Redis), or mount the data from the web app (Sidekiq). They are ties together via the following docker

Docker Unknown flag --mount

偶尔善良 提交于 2019-12-08 16:27:54
问题 I want to mount a directory from the host to a container using the mount flag over volume but I am getting ` This is only experienced when using mount flag and not with volume *Command:* docker run -d -it --name devtest --mount type=bind,source="$(pwd)",target=/home/ httpd Error unknown flag: --mount Server Version: 1.13.1 Storage Driver: aufs Dirperm1 Supported: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host macvlan null overlay Swarm: