473,382 Members | 1,651 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,382 software developers and data experts.

STL:invoking a member of an object not in the container

I have a std::vector<Vec3*> _vertices and an object BoundingBox _bbox. _bbox
has a member function called void expandBy(Vec3& v); I want to call
_bbox.expandBy on every member of _vertices. I know I can loop through and
do that. I also know I can create a function object and pass it. The
latter can be pretty slick, if I will be doing it a lot. It seems more
trouble than it's worth to do it for only one function in one class.
AFAIK, there is no way to use things such as mem_fun to do that. They
apply to the objects in the container being iterated over by the STL
algorithm.

Is there a way to accomplish what I want with the STL algorithms? Boost?
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell

Jul 23 '05 #1
1 1092
Steven T. Hatton wrote:
I have a std::vector<Vec3*> _vertices and an object BoundingBox _bbox. _bbox
has a member function called void expandBy(Vec3& v); I want to call
_bbox.expandBy on every member of _vertices. I know I can loop through and
do that. I also know I can create a function object and pass it. The
latter can be pretty slick, if I will be doing it a lot. It seems more
trouble than it's worth to do it for only one function in one class.
AFAIK, there is no way to use things such as mem_fun to do that. They
apply to the objects in the container being iterated over by the STL
algorithm.

Is there a way to accomplish what I want with the STL algorithms? Boost?


Actually, using 'bind1st' and 'mem_fun' should be enough, no need for
Boost. I can never remember the right order of things, takes me a couple
of tries to get it right, but the direction is something like

BoundingBox _bbox;
for_each(_vertices.begin(), _vertices.end(),
bind1st(mem_fun(&BoundingBox::expandBy), &_bbox));

V
Jul 23 '05 #2

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

Similar topics

7
by: jose luis fernandez diaz | last post by:
Hi, Is this right any stl container (vector, deque, list, . . .)? typedef vector container; int main() { container<int> c1;
5
by: Johan | last post by:
Hi, Hi like to create a linked list with a template class ( see below ). How to make one using the STL container list. I want to create a linked list with different kind of types i.e....
4
by: joetekubi | last post by:
hello all, while working with STL containers and various class composition, I can across a bug that I can't seem to find. When using a STL container in a derived class with composition,...
6
by: Joseph Turian | last post by:
Without modifying the STL code directly, what's the *simplest* way to extend an STL container by adding a method to it? e.g. I want to add method foo() to list<T>. Can I do this without...
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'...
4
by: Marko.Cain.23 | last post by:
How can I copy elements from one STL container to another STL container if a condition is met and if it find an element fails that condition, it stops the copying? I can't use the original...
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...
4
by: Sarath | last post by:
>From the documentation of MSDN, it is saying that bitset is not a STL container Unlike the similar vector<boolClass, the bitset class does not have iterators and is not an Standard Template...
17
by: mosfet | last post by:
Could someone tell me why it's considered as bad practice to inherit from STL container ? And when you want to customize a STL container, do you mean I need to write tons of code just to avoid to...
7
by: ademirzanetti | last post by:
Hi there !!! I would like to listen your opinions about inherit from a STL class like list. For example, do you think it is a good approach if I inherit from list to create something like...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.