Руководство по стандартной библиотеке шаблонов STL

double x_) const


#include <iostream.h> #include <math.h> #include <stl.h>

struct square_root : public unary_function<double, double> { square_root () {} double operator () ( double x_) const { return sqrt (x_); } };

int input [3] = { -1, -4, -16 };

int main () { int output [3]; transform (input, input + 3, output, unary_compose<square_root, negate<int> > (square_root (), negate<int> ())); for (int i = 0; i < 3; i++) cout << output[i] << endl; return 0; }



#include <iostream.h> #include <math.h> #include <stl.h>

struct square_root : public unary_function<double, double> { square_root () {} double operator () ( double x_) const { return sqrt (x_); } };

int input [3] = { -1, -4, -16 };

int main () { int output [3]; transform (input, input + 3, output, compose1 (square_root (), negate<int> ())); for (int i = 0; i < 3; i++) cout << output[i] << endl; return 0; }


Содержание раздела