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 31,418 of 33,346   
   Seungbeom Kim to gast128@hotmail.com   
   Re: any_of, all_of, none_of   
   26 Aug 11 19:18:34   
   
   a1a5d93d   
   From: musiphil@bawi.org   
      
   On 2011-08-23 18:49, gast128@hotmail.com wrote:   
   >   
   > I was wondering why the c++ committee didn't decide to stick to the   
   > '_if' convention as used in other STL algorithm, like all/all_if,   
   > any / any_if etc.   
   >   
   > These new algorithms seems only be defined for use with predicates.   
   > But what if u just want to use these for testing against a value, you   
   > now have to bind an argument to an equal_to structure.   
      
   I think they come from two different origins. Those that have the "_if"   
   suffix are all verbs that take some action, on the entire sequence without   
   the suffix or only on some qualifying items with the suffix: find[_if],   
   count[_if], copy[_if], replace[_copy][_if], remove[_copy][_if], etc.   
      
   On the other hand, all_of, any_of and none_of come from the background   
   of logic, and act as logical quantifiers yielding Boolean values:   
   given a predicate P and a sequence X, you get   
      
        all_of(X, P)  which corresponds to  ∀x∈X P(x),   
        any_of(X, P)  which corresponds to  ∃x∈X P(x), and   
       none_of(X, P)  which corresponds to  ∄x∈X P(x) (or ¬∃x∈X P(x)).   
      
   So it's a very natural choice that they take predicates.   
   And it's not a serious limitation, for you can make predicates easily   
   (using functors or lambda expressions) that match a specific value.   
      
   --   
   Seungbeom Kim   
      
      
         [ 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