473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

filtering items in a container

I am trying to write a filtering algorithm without reinventing the
wheel. I basically want to select items in a container that have a
certain 'property' - i.e. satisfy a certain criteria - to be provided by
a predicate function.

In pseudocode, it would look something like this:

template <class T1 /*container type*/, typename T2/* type held in
container*/>
T1<T2filter(const T1<T2>& source, PredicateFunctor func)
{
T1<T2filtered_output ;
std::for_each(source.begin(), source.end(), func());
//somehow append those matching to variable filtered_output
return filtered_output ;
}

The idea is so that I could use such an algorithm to filter or 'select'
items that match certain criteria from an STL container - e.g. a vector
or map of objects.

if there is an existing STL algo that does that - or you can thing of a
better way of doing (implementing) this, please let me know
Oct 27 '07 #1
3 2612
On 2007-10-27 10:19, Anonymous wrote:
I am trying to write a filtering algorithm without reinventing the
wheel. I basically want to select items in a container that have a
certain 'property' - i.e. satisfy a certain criteria - to be provided by
a predicate function.

In pseudocode, it would look something like this:

template <class T1 /*container type*/, typename T2/* type held in
container*/>
T1<T2filter(const T1<T2>& source, PredicateFunctor func)
{
T1<T2filtered_output ;
std::for_each(source.begin(), source.end(), func());
//somehow append those matching to variable filtered_output
return filtered_output ;
}

The idea is so that I could use such an algorithm to filter or 'select'
items that match certain criteria from an STL container - e.g. a vector
or map of objects.

if there is an existing STL algo that does that - or you can thing of a
better way of doing (implementing) this, please let me know
Sounds like remove_copy_if().

--
Erik Wikström
Oct 27 '07 #2
Anonymous wrote:
I am trying to write a filtering algorithm without reinventing the
wheel. I basically want to select items in a container that have a
certain 'property' - i.e. satisfy a certain criteria - to be provided by
a predicate function.

In pseudocode, it would look something like this:

template <class T1 /*container type*/, typename T2/* type held in
container*/>
T1<T2filter(const T1<T2>& source, PredicateFunctor func)
{
T1<T2filtered_output ;
std::for_each(source.begin(), source.end(), func());
//somehow append those matching to variable filtered_output
return filtered_output ;
}

The idea is so that I could use such an algorithm to filter or 'select'
items that match certain criteria from an STL container - e.g. a vector
or map of objects.

if there is an existing STL algo that does that - or you can thing of a
better way of doing (implementing) this, please let me know
http://www.boost.org/libs/iterator/d..._iterator.html
Oct 27 '07 #3


Juraj Ivančić wrote:
Anonymous wrote:
>if there is an existing STL algo that does that - or you can thing of
a better way of doing (implementing) this, please let me know


http://www.boost.org/libs/iterator/d..._iterator.html
Wow, this is EXACTLY what I'm looking for. The BOOST library is quickly
becoming my favourite C++ library ! ;)
Oct 27 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Joe exCSSive | last post by:
Hi, folks: I'm back...and now I'm really stuck !! I have a graphic ( http://www.sundialontario.com/images/makeitatable.jpg ) that I would like to convert to CSS and I'm not sure how to do...
5
by: Richard | last post by:
Hi, I have a form that take some time to load due to many comboboxes and at least 8 subforms. When I filter or sort the main form I get an error message and then Access shuts down. They ask if...
1
by: Alan Silver | last post by:
Hello, I have a page in which I'm trying to give the user the chance to manipulate a list of items. These are the price variations for a product, so each item consists of a name (eg, small,...
6
by: marcwentink | last post by:
Could you please advise me what C++ STL container I could use that would automaticly only store unique items. Hence prevents the insertion of doubles. It should behave like this, (I use 'vector'...
2
by: JUAN ERNESTO FLORES BELTRAN | last post by:
Hi you all, I am developping a python application which connects to a database (postresql) and displays the query results on a treeview. In adittion to displaying the info i do need to implement...
18
by: Hunk | last post by:
Would like some advice on the fillowing I have a sorted list of items on which i require to search and retrieve the said item and also modify an item based on its identity. I think an Map stl...
2
by: Newbe developer | last post by:
I have a question how I can evaluate the item values. I want to know which radiobutton is true in order to save the value it represents. the code is this: <asp:Repeater id="futuregames"...
1
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I've got a ListBox on my Visual Studio C# form with several entries (14,000). I have to put a search field on the form. As text is entered into the search field, I want the ListBox to remove...
2
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I've got a ListBox on my form with lots of data in it (14000 entries). I have to put a search field on the form. As text is entered into the search field, I want the ListBox to remove entries...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.