containers

Type-safe generic containers with macros

浪尽此生 提交于 2019-12-01 04:05:12
问题 I'm trying to make a type-safe generic linked list in C using macros. It should work similarly to how templates work in C++. For example, LIST(int) *list = LIST_CREATE(int); My first attempt was for #define LIST(TYPE) (the macro I used above) to define a struct _List_##TYPE {...} . That, however, did not work because the struct would be redefined every time I declared a new list. I remedied the problem by doing this: /* You would first have to use this macro, which will define the `struct

inline-block overflowing outside container

╄→гoц情女王★ 提交于 2019-12-01 04:03:51
问题 I have a container that I don't want to set as inline-block and that contains inline-block elements. These elements will overflow out of the container instead of extending it. How can I manage to prevent this behaviour ? Demo #inline-block-container { background-color: red; white-space:nowrap; } .inline-block-element { background-color: blue; width: 50px; height: 30px; margin: 10px; display:inline-block; } In this demo, I would like the red rectangle to expand (even out of viewport) to

Looking for a data container with O(1) indexing and O(log(n)) insertion and deletion

主宰稳场 提交于 2019-12-01 03:43:52
I'm not sure if it's possible but it seems a little bit reasonable to me, I'm looking for a data structure which allows me to do these operations: insert an item with O(log n) remove an item with O(log n) find/edit the k'th-smallest element in O(1), for arbitrary k (O(1) indexing) of course editing won't result in any change in the order of elements. and what makes it somehow possible is I'm going to insert elements one by one in increasing order. So if for example I try inserting for the fifth time, I'm sure all four elements before this one are smaller than it and all the elements after this

Docker at Windows 10 proxy propagation to containers not working

拥有回忆 提交于 2019-12-01 03:39:56
I am behind cooperate proxy and running docker on windows 10. I have setup the proxy on docker as per the documentation here . I am able to pull images but these proxy settings are not propagating to containers e.g. when I run alpine env, it does not show proxy conf. Below is my output λ docker run alpine env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOSTNAME=14fca5bee12f HOME=/root Following is the expected output as per the documentation. On building following docker file, I get connection errors from alpine container Docker Version Docker version 17.12.0-ce, build

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

爱⌒轻易说出口 提交于 2019-12-01 03:27:22
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 ? In addition to your own suggestion, if your compiler supports C++0x lambda expressions, you can use this shorter version:

Connect to host mongodb from docker container

落花浮王杯 提交于 2019-12-01 03:26:01
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 is not the host's localhost. I already read many stackoverflow posts on this, I already tried using: -

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

99封情书 提交于 2019-12-01 03:13:57
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. 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 . std::queue is not thread safe if one or more threads are writing. And its interface is not conducive to a thread safe

set_union with multiset containers?

感情迁移 提交于 2019-12-01 03:04:08
问题 What's the return of the algorithm std:set_union when one or both input containers are multisets with duplicated objects? Do dups get lost? Let's suppose for example: multiset<int> ms1; ms1.insert(1); ms1.insert(1); ms1.insert(1); ms1.insert(2); ms1.insert(3); multiset<int> ms2; ms2.insert(1); ms2.insert(1); ms2.insert(2); ms2.insert(2); ms2.insert(4); vector<int> v(10); set_union( ms1.begin(), ms1.end(), ms2.begin(), ms2.end(), v.begin() ); What would the output be? 回答1: From the standard,

limit size of Queue<T> in C++

久未见 提交于 2019-12-01 02:51:36
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 the 3rd item, the 1st item will be automatically popped out before pushing the new item. How to

Checking if a sequence container is contiguous in memory

99封情书 提交于 2019-12-01 02:28:39
Is there a way to check if a sequence container is contiguous in memory? Something like: #include <iostream> #include <vector> #include <deque> #include <array> int main() { std::cout << std::boolalpha; std::cout << is_contiguous<std::vector<int>>::value << '\n' // true std::cout << is_contiguous<std::deque<int>>::value << '\n'; // false std::cout << is_contiguous<std::array<int, 3>>::value << '\n'; // true } Clarification This question is referring to type traits, rather than the properties of a specific instance of a type. No , there is not compiletime trait for this. The draft C++1z