home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 32,519 of 33,346   
   Marco Guazzone to All   
   Re: Best way to pass a map-like containe   
   31 Aug 12 14:16:36   
   
   From: marco.guazzone@googlemail.com   
      
   { Empty lines in quoted sections removed -mod }   
      
   On Friday, August 31, 2012 12:13:36 AM UTC+2, Daniel Krügler wrote:   
   [cut]   
      
   > > But, when the container is a map (or similar), what do you use?   
   >   
   > It certainly depends what you want to realize. There are clearly   
   > reasonable use-cases, where the associative container can be   
   > considered as a sequence of elements. This makes sense, because   
   > associative containers and unordered containers also satisfy the   
   > Container requirements.   
   >   
   > > Possibile candidates:   
   > >   
   > > 1. Two parameters: the first/last iterator pair:   
   > >       map<...,...> m;   
   > >       foo(m.begin(), m.end())   
   >   
   > Yes, this is IMO a very intuitive one. But you may need to explain   
   > what foo is going to do, before we speculate on that.   
      
   You're right.   
   In fact, a possible issue with this signature is when you pass   
   iterators to multimap. 'foo', to work correctly, should not make any   
   assumption on the uniqueness of the first element of each pair.   
      
   Maybe, in that case, it would be better to directly pass the container?   
      
   > > 2. Four parameters: the first/last iterator pair representing the   
   [cut]   
   >   
   > I do'n see much value of this signature, but I certainly think that   
   > it would be nice to have a view on std::map that solely iterates   
   > over its keys or over its values. Java's Map interface provides   
   > these views and I would say that these two views are quite often   
   > used.   
      
   Yes I agree. In addition to Java, there're many other languages that   
   have them (e.g., D, Perl, PHP and Python, just to name a few). It's a   
   pity that C++11 does not have them, or am I wrong?   
      
   [cut]   
      
   > I would consider as a different approach that accepts a range as   
   > argument. Certainly this approach is often very useful as well, for   
   > any container. The very advantage is that the caller has no chance   
   > to provide a wrong combination of iterator arguments.   
      
   Interesting. I assume you're referring to Boost.Range, are you?   
      
   Cheers,   
      
   -- Marco   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca