containers

C++ algorithm like python's 'groupby'

旧巷老猫 提交于 2019-11-29 17:38:43
问题 Are there any C++ transformations which are similar to itertools.groupby()? Of course I could easily write my own, but I'd prefer to leverage the idiomatic behavior or compose one from the features provided by the STL or boost . #include <cstdlib> #include <map> #include <algorithm> #include <string> #include <vector> struct foo { int x; std::string y; float z; }; bool lt_by_x(const foo &a, const foo &b) { return a.x < b.x; } void list_by_x(const std::vector<foo> &foos, std::map<int, std:

Can 'iterator' type just subclass 'const_iterator'?

纵饮孤独 提交于 2019-11-29 17:38:00
问题 After another question about iterators I'm having some doubts about custom containers. In my container, iterator is a subclass of const_iterator , so that I get conversion from non-const to const "for free". But is this allowed or are there any drawbacks or non-working scenarios for such a setup? 回答1: Yes, this is fine. This is how VC10's implementation of the iterators for vector are structured, for example. See _Vector_iterator and _Vector_const_iterator in <vector> . By the way, writing

Is docker a solution for making application cross platform?

瘦欲@ 提交于 2019-11-29 17:00:59
问题 I'm getting started with docker by reading some blogs and introduction material. My understanding is docker can wrap a single application into a standardized container. The container provides a sandbox, all the necessary resources the application needs to run, and the application inside always live within that container. That means I can ship the container to everywhere( different kind of OS or even cloud platforms ) and it should still can be run correctly. If my understanding is correct,

STL algorithms taking the whole container rather than .begin(), end() as arg?

房东的猫 提交于 2019-11-29 16:50:49
问题 Stand-alone STL algorithms (like std::count_if ) take pair of iterators. In all cases where I use those (and in all examples I've seen online!), I find myself typing std::count_if(myContainer.begin(),myContainer.end(), /* ... */ ); Is there a reason why shorthand templates of the style std::count_if(myContainer, /* ... */ ); are not provided, given that more of than not is the operaation performed on the whole container? Did I just overlook it? Is the answer different for c++11 and c++03? 回答1

Check if in “dev” mode inside a Controller with Symfony

你说的曾经没有我的故事 提交于 2019-11-29 15:56:16
问题 When using dev mode with a Symfony2.x application, one usually works in locale. Hence, such function does not works as expected (for instance, try to get the current IP under localhost). This could be a problem, e.g. when one try to use such ip-based web service. Hence, I just want to know how to check inside a controller if the Symfony2 application is running in dev mode or not . In that way one can set the behavior of the controller depending by the mode. Any idea? 回答1: To get the current

Can we deploy an asp.net mvc 4 app to docker with windows container?

穿精又带淫゛_ 提交于 2019-11-29 15:38:29
问题 All the demo I saw lately are oriented Asp.net core (I am not sure how it's stable and functional, as it didn't contain all asp.net features), as Windows server 2016 support containers (and docker), should we be able to deploy an asp.net mvc 4.0 app ? 回答1: Yes. You can use microsoft/windowsservercore or microsoft/iis as a base image, install full ASP.NET and run your 'legacy' .NET apps in containers on Windows. You can do it now with Windows 10 and Server 2016 TP5, but the RTM (expected next

C++ How to create a heterogeneous container

不问归期 提交于 2019-11-29 15:26:51
问题 I need to store a series of data-points in the form of (name, value), where the value could take different types. I am trying to use a class template for each data-point. Then for each data-point I see, I want to create a new object and push it back into a vector. For each new type, I need to create a new class from the template first. But I can not store the objects created in any vector, since vectors expect the same type for all entries. The types I need to store can not be fitted in a

Obtain iterator from pointer or reference

回眸只為那壹抹淺笑 提交于 2019-11-29 14:54:02
I would like to know if it is possible to obtain an iterator to an object inside a container (e.g. std::vector<...> ) by only having access to the object inside the container, e.g. through a reference (which implies we have access to a pointer to it using the & operator). For example, normally we declare an iterator as std::vector<int>::iterator = vec.begin(); or std::vector<int>::iterator = next(vec.begin(), idx); but in the first example we are most probably about to iterate through the container, in order, while in the second example we know the index of the object we require. I would like

cast list<A*> to list<B*> where B inherits A

廉价感情. 提交于 2019-11-29 14:47:47
I got a function void doSomething(list<A*> list1, list<A*> list2) And classes class B : A class C : A Is there a direct way to call my function like void doSomething(list<B*> listOfB, list<C*> listOfC) or do I have to wrap it manually like void doSomething(list<B*> listOfB, list<C*> listOfC) { list<A*> l1; list<A*> l2; for (B* b : listOfB) l1.insert(b); for (C* c : listOfC) l2.insert(c); doSomething(l1, l2); //calling the function taking supertype } I tried unsuccessfully to cast list<B*> to list<A*> , my guess is that due to template specialization, the compiler consider list<B*> and list<A*>

What is the C++ equivalent of inheriting a Java collection interface (Set, Map, List etc.)? Or extending AbstractCollection?

好久不见. 提交于 2019-11-29 14:38:15
I've started coding in C++, coming from a Java background (actually I'd studied C++ at my university, but we never got to the STL etc.) Anyway, I've gotten to the point where I'm arranging data in all sorts of collections, and I immediately tell myself "Ok, this is a kind of a Set; and this is a List, or an ArrayList; and this is a map etc." In Java, I would simply have whatever class I'm writing implement the Set or Map or List interface; but I would probably not go as far as inheriting ArrayList or HashSet or what-not, the implementations there are kind of involved and I wouldn't want to