containers

How can I write a generic container class that implements a given interface in C#?

左心房为你撑大大i 提交于 2019-11-27 11:49:18
Context: .NET 3.5, VS2008. I'm not sure about the title of this question, so feel free to comment about the title, too :-) Here's the scenario: I have several classes, say Foo and Bar, all of them implement the following interface: public interface IStartable { void Start(); void Stop(); } And now I'd like to have a container class, which gets an IEnumerable<IStartable> as an argument in its constructor. This class, in turn, should also implement the IStartable interface: public class StartableGroup : IStartable // this is the container class { private readonly IEnumerable<IStartable>

Ad hoc polymorphism and heterogeneous containers with value semantics

三世轮回 提交于 2019-11-27 11:21:23
I have a number of unrelated types that all support the same operations through overloaded free functions (ad hoc polymorphism): struct A {}; void use(int x) { std::cout << "int = " << x << std::endl; } void use(const std::string& x) { std::cout << "string = " << x << std::endl; } void use(const A&) { std::cout << "class A" << std::endl; } As the title of the question implies, I want to store instances of those types in an heterogeneous container so that I can use() them no matter what concrete type they are. The container must have value semantics (ie. an assignment between two containers

What is the right approach when using STL container for median calculation?

你。 提交于 2019-11-27 11:19:52
Let's say I need to retrieve the median from a sequence of 1000000 random numeric values. If using anything but std::list , I have no (built-in) way to sort sequence for median calculation. If using std::list , I can't randomly access values to retrieve middle (median) of sorted sequence. Is it better to implement sorting myself and go with e.g. std::vector , or is it better to use std::list and use std::list::iterator to for-loop-walk to the median value? The latter seems less overheadish, but also feels more ugly.. Or are there more and better alternatives for me? Any random-access container

Understanding servlet container

纵饮孤独 提交于 2019-11-27 11:17:08
问题 As a UI devloper and someone with very limited Java knowledge, how do I understand what exactly is servlet container in simple terms ? I have heard Weblogic, JBoss, etc are servlet containers, but not sure what that means exactly. Does it mean any middleware technology ? Could you please help me. 回答1: A servlet container is an application server that implements some version of the Java Servlet Specification. In a nutshell, the servlet spec defines a programming model that allows a developer

General use cases for C++ containers

房东的猫 提交于 2019-11-27 10:37:21
What are the general use cases for the C++ standard library containers ? bitset deque list map multimap multiset priority_queue queue set stack vector For example, a map is generally better for a paired search. Tomasz Łazarowicz A picture is worth a thousand words. It's available from nolyc , the informative bot of ##C++ on Freenode, using the command "container choice" or "containerchoice". The link to this picture you receive in response is hosted at adrinael.net , which suggests we should thank Adrinael , member of Freenode's ##C++ community. Kiril Kirov bitset - used to store bits. General

What's the difference between ClusterIP, NodePort and LoadBalancer service types in Kubernetes?

走远了吗. 提交于 2019-11-27 10:01:30
1 - I'm reading the documentation and I'm slightly confused with the wording. It says: ClusterIP : Exposes the service on a cluster-internal IP. Choosing this value makes the service only reachable from within the cluster. This is the default ServiceType NodePort : Exposes the service on each Node’s IP at a static port (the NodePort). A ClusterIP service, to which the NodePort service will route, is automatically created. You’ll be able to contact the NodePort service, from outside the cluster, by requesting <NodeIP>:<NodePort> . LoadBalancer : Exposes the service externally using a cloud

How to create WPF usercontrol which contains placeholders for later usage

心不动则不痛 提交于 2019-11-27 10:00:19
问题 I'd better ask the question by example. Let's say I have UserControl and Window which uses this control. I would like to design this control (named MyControl) in such way (this is sci-fi syntax!): <Grid> <Button>Just a button</Button> <PlaceHolder Name="place_holder/> </Grid> and use in such ways when designing my Window: <MyControl/> or <MyControl> <place_holder> <Button>Button 1</Button> </place_holder> </MyControl> or <MyControl> <place_holder> <Button>Button 1</Button> <Button>Button 2<

'Multipurpose' linked list implementation in pure C

限于喜欢 提交于 2019-11-27 09:32:56
问题 This is not exactly a technical question, since I know C kind of enough to do the things I need to (I mean, in terms of not 'letting the language get in your way'), so this question is basically a 'what direction to take' question. Situation is: I am currently taking an advanced algorithms course, and for the sake of 'growing up as programmers', I am required to use pure C to implement the practical assignments (it works well: pretty much any small mistake you make actually forces you to

Template class with template container

我是研究僧i 提交于 2019-11-27 09:28:56
问题 How can I declare template class (adaptor) with different containers as template arguments? For example, I need to declare class: template<typename T, typename Container> class MyMultibyteString { Container buffer; ... }; And I want it to my based on vector. How to make it hard-defined? (to prevent someone from writing such declaration MyMultibyteString<int, vector<char>> ). Moreover, how to implement such construction: MyMultibyteString<int, std::vector> mbs; without passing template

Shrink-wrap and center a container for inline-block elements

冷暖自知 提交于 2019-11-27 09:26:29
I have a bunch of inline-block elements over several lines which I'd like to center horizontally. The inline-block elements all have the same fixed size, but I'd like the centering to be able to handle page resizing and adding or removing elements. I've stripped down the html/css and removed the attempt at centering for clarity. It's at http://jsfiddle.net/fe25H/1/ If you resize the results window so that the third inline-block element drops down, the container fills the width and we get this: -----------------BODY------------------ | | ||-------------CONTAINER-------------|| ||-INLINEBLOCK--