Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      C++ named requirements:Predicate

      From cppreference.com
      <cpp‎ |named req
       
       
      C++ named requirements
       

      ThePredicate requirements describe a callable that returns aBooleanTestable value.

      Predicate is typically used with algorithms that take input data (individual objects/containers) and a predicate, which is then called on input data to decide on further course of action. Some examples of predicate usage in C++ standard library are:

      • std::all_of,std::any_of,std::none_of Take an array of elements and a predicate as an input. Call predicate on individual input elements, and return true if for all/any/none elements, predicate returns true.
      • std::find_if Take sequence of elements, and a predicate. Return first element in the sequence, for which predicate returns value equal totrue.

      Description of algorithm facilities, given above, is crude and intended to explainPredicate in simple terms. For detailed info, refer to individual pages.

      In other words, if an algorithm takes aPredicatepred and an iteratorfirst, it should be able to test the object of the type pointed to by the iteratorfirst using the given predicate via a construct likeif(pred(*first)){/*...*/}.

      The function objectpred shall not apply any non-constant function through the dereferenced iterator and must accept aconst argument, with the same behavior regardless of whether the argument isconst or non-const. This function object may be a pointer to function or an object of a type with an appropriate function call operator.

      [edit]Requirements

      This section is incomplete
      Reason: better describe actual requirements

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 3031C++98requirements onconst values were insufficentrequirements strengthened

      [edit]See also

      (C++20)
      specifies that a callable type is a Boolean predicate
      (concept)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/named_req/Predicate&oldid=175973"

      [8]ページ先頭

      ©2009-2025 Movatter.jp