Thanks a lot for your advice, RRick.
I'm hoping that if I create the vector within a method and then return this vector, the additional copy will be removed by most modern compilers (return value optimisation).
Is this generally the case in your experience?
Many thanks,
Paul
User Profile
Collapse
-
Thanks a lot, weaknessforcats .
No, I am not using STL; it's my own custom functor.
I prefer your syntax, as it emphasises the function call semantics, rather than the "operator() ".
Many thanks,
PaulLeave a comment:
-
Hi Rick,
Many thanks for your reply.
I do indeed feel uneasy about breaking encapsulation.
As far as the vector of keys is concerned, it's far from ideal, but I would make it part of the contract that this is only a snapshot, or a memento (although not in the strict Design Patterns sense of the word). Then I believe it should be OK.
This said, does the code that I pasted in my first message...Leave a comment:
-
Calling operator() via a Pointer
Hi all,
A very simple question, but I couldn't find a definitive answer in the literature. Functors provide you with the function call syntax:
may be a call to a functor. Now, what if I have a pointer to a functor instead? Is the following syntax the recommended, or perhaps the only, way to call operator() on a functor pointer:Code:foo(1, 2, 3)
Many thanks!Code:fooPtr->operator()(1, 2, 3)
Regards,... -
RRick,
I'm concerned with two use cases.
First, I need to be able to produce a memento of the map. However, I don't care about the values for this purpose, I only need to remember the keys.
Second, I have a data structure whose underlying implementation (via composition) is a hash_map. I want to keep this data structure as simple as possible, so I don't want to make it (anywhere near) STL compliant and...Leave a comment:
-
Saving hash_map keys in a vector
Hi,
Is there a more elegant and/or efficient way of saving the keys from a hash_map in a vector? Perhaps using assign or other algorithms? The problem, of course, is that we are dealing with an iterator of pairs...
...Code:hash_map<string, void *> hashMap; // ... vector<string> keys; keys.reserve(hashMap.size()); hash_map<string, void *>::iterator endIter
No activity results to display
Show More
Leave a comment: