User Profile

Collapse

Profile Sidebar

Collapse
Paul Bilokon
Paul Bilokon
Last Activity: Nov 25 '07, 01:46 AM
Joined: Nov 13 '07
Location: London, UK
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Paul Bilokon
    replied to Saving hash_map keys in a vector
    in C
    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
    See more | Go to post

    Leave a comment:


  • Paul Bilokon
    replied to Calling operator() via a Pointer
    in C
    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,
    Paul
    See more | Go to post

    Leave a comment:


  • Paul Bilokon
    replied to Saving hash_map keys in a vector
    in C
    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...
    See more | Go to post

    Leave a comment:


  • Paul Bilokon
    started a topic Calling operator() via a Pointer
    in C

    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:
    Code:
    foo(1, 2, 3)
    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:
    fooPtr->operator()(1, 2, 3)
    Many thanks!

    Regards,...
    See more | Go to post

  • Paul Bilokon
    replied to Saving hash_map keys in a vector
    in C
    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...
    See more | Go to post

    Leave a comment:


  • Paul Bilokon
    started a topic Saving hash_map keys in a vector
    in C

    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
    ...
    See more | Go to post
No activity results to display
Show More
Working...