1

Topic: Algorithms returning dial-ups, or...

Question especially practical... Is type such://the interface class A {public: A (); virtual ~A () = 0; int GetValueA (); char* GetValueB ();} ;//it is used polymorphicly class B: public A {public: ~B () {} int GetValueA (); char* GetValueB (); long GetValueC ();...//here still can be  };//all it in what that the container, for simplicity let std:: vector <A *>. std:: vector <A *> vecA;//here the data is always live, is not deleted, does not change... It would be desirable function which will address to this container, and on the basis of values returned  objects of class B,  returned. But what? A dial-up? New std:: vector? Range? Looked towards algorithms at returning dial-ups, type std:: copy_if. int Func (const std::vector<A*>& in, std::vector<A*>& out) {out.resize (in.size(); auto it = std:: copy_if (in.begin (), in.end (), out.begin (), [and] (A* b)-> bool {if (b. GetValueA ()) return true; if (b. GetValueB ()) return false;//etc., on the basis of values  we make the decision, to copy or not}); out.resize (std:: : distance (out.begin (), it));} And so it is done often, sampling of the container on what that to conditions on the basis of values . Especially constant copying seems  not effectively.

2

Re: Algorithms returning dial-ups, or...

Hello, Dead Down, you wrote: > the Question especially practical... > >//all it in what that the container, for simplicity let std:: vector <A *>. > std:: vector <A *> vecA;//here the data is always live, is not deleted, does not change... > > It would be desirable function which will address to this container, and on the basis of values returned  objects of class B,  returned. But what? A dial-up? New std:: vector? Range? > Looked towards algorithms at returning dial-ups, type std:: copy_if. > And so it is done often, sampling of the container on what that to conditions on the basis of values . > especially constant copying Seems  not effectively. Copying of a vector of pointers in other vector on idea very cheap operation so I to begin with would check up that it really influences productivity. Still not bad to know usage scenarios  . Since The container always live also does not change, it is possible  a proxy-wrapper, with  the interface, for example such: struct Selection {Selection (std::vector<A*>&, std:: function <bool (A *)> predicate); std:: vector <A *>:: iterator begin () const; std:: vector <A *>:: iterator end () const;}

3

Re: Algorithms returning dial-ups, or...

Hello, Dead Down, you wrote: > especially constant copying Seems  not effectively. In go and Rust there is such piece as slice, in With ++ it like does not work for , but it is possible  on range , i.e. it is not necessary to copy anything simply   on   iterators began also the end.

4

Re: Algorithms returning dial-ups, or...

Hello, Dead Down, you wrote: > the Question especially practical... > Is type such: >... > std:: vector <A *> vecA;//here the data is always live, is not deleted, does not change... > [/ccode] > It would be desirable function which will address to this container, and on the basis of values returned  objects of class B,  returned. But what? A dial-up? New std:: vector? Range? forward iterator as regex_token_iterator If it is necessary to save the found objects it is possible somehow so://sorted set is needed for intersection set <string> sorted_unique_tokens (const string &input, const string &regex) {//passing-1 as the submatch index parameter performs splitting std:: regex re (regex); sregex_token_iterator first {input.begin (), input.end (), re,-1}; sregex_token_iterator last; return {first, last};}

5

Re: Algorithms returning dial-ups, or...

Hello, Dead Down, you wrote: > It would be desirable function which will address to this container, and on the basis of values returned  objects of class B,  returned. But what? A dial-up? New std:: vector? Range? I think, it is necessary to look aside Range library. In particular, this piece: struct Selection {Selection (std::vector<A*>&, std:: function <bool (A *)> predicate); std:: vector <A *>:: iterator begin () const; std:: vector <A *>:: iterator end () const;} it is very similar on ranges:: view:: filter. So, it is necessary to return or the new container, or ranges:: view:: xxxx. By the way, somebody densely worked with ranges? To return from function any ranges:: view:: xxxx it it is good or bad?

6

Re: Algorithms returning dial-ups, or...

Hello, ViTech, you wrote: VT> Hello, Dead Down, you wrote: >> It would be desirable function which will address to this container, and on the basis of values returned  objects of class B,  returned. But what? A dial-up? New std:: vector? Range? VT> I Think, it is necessary to look aside Range library. In particular, this piece: VT> struct Selection {VT> Selection (std::vector<A*>&, std:: function <bool (A *)> predicate); VT> std:: vector <A *>:: iterator begin () const; VT> std:: vector <A *>:: iterator end () const; VT>} it is very similar on ranges:: view:: filter. So, it is necessary to return or the new container, or ranges:: view xxxx. 1) Or not to return anything, and to transfer  parameter which will do the necessary: template <class RangeT> void ProcessSelection (RangeT and rng, std:: function <bool (typename RangeT:: value_type)> pred, std:: function <void (typename RangeT:: : value_type)> const and action) {... if (pred (a)) action (a);...} 2) Still it is possible to write  the iterator with the help boost:: iterator_facade is, most likely, the same, as ranges:: v3:: view:: filter, only a side view. VT> by the way, somebody densely worked with ranges? To return from function any ranges:: view:: xxxx it it is good or bad? It can not work, if lifetime of objects on which iterate iterators (they after all there inside ?), will be insufficiently long, for example. It is logical to use the received range "on the fly", instead of to store it somewhere, and therefore problems should not be, except for cases when ranges (their any type conversions reversed_range) "accumulate" and somewhere there is "a premature evacuation" transient objects.