Three sources of functions

xiaoxiao2021-03-06  55

Function objects can be considered as a template mechanism. There are two advantages over the function object and function pointer: 1. If the overloaded call operator is an inline function, the compiler can perform inline compilation, provide possible performance benefits; 2. Function object can have any number Additional data, uses these data to buffer results, or buffer the data that helps the current operation. Source of the function object: 1. Standard library predefined a set of arithmetic, relationships, and logical functions. Less: Less Less intless; Ires = intless (Ival1, Ival2); Ires = count_if (sVec.begin (), svec.end ()), LESS (), sval1); 2, A set of predefined function adapters allow us to specialize or extensions for predefined function objects (or even any function objects). Count_if (vec.begin (), vec.end (), not1 (Bind2nd (Less_equal (), 10)))); 3, we can define your own function object, pass it to generic algorithm, or will They pass to the function adapter.

转载请注明原文地址:https://www.9cbs.com/read-82096.html

New Post(0)