template <class T, class Integer>
inline T power(T x, Integer n);
template <class T, class Integer, class MonoidOperation>
T power(T x, Integer n, MonoidOperation op);
The first version of
The second version of
Important note:
Defined in the standard header numeric, and in the nonstandard backward-compatibility header algo.h. This function is an SGI extension; it is not part of the C++ standard.
For the first version:
For the second version:
The number of multiplications (or, in the case of the second version, the number of applications of
int main() {
cout << '2 ** 30 = ' << power(2, 30) << endl;
}
[1] This is a conceptual description of what
[2] See the Monoid Operation requirements for a discussion of associativity.
[3] This is in fact not the minimum possible number of multiplications: it is possible to compute the fifteenth power of
Monoid Operation,
Function Objects
Introduction
Category: functors
Component type: overview
A
The basic function object concepts are Generator, Unary Function, and Binary Function: these describe, respectively, objects that can be called as
Function objects that return
There is an important distinction, but a somewhat subtle one, between function objects and
Adaptable function objects are important because they can be used by