8.2(목) C++ - transform

from Study/C++ 2007/08/02 20:16 view 19853

// transform 에 대해서

int foo( int a, int b )

{

        return a + b;

}


// functional
헤더파일에서 지원한다.

template<typename T> struct plus

{

        T operator()( T a, T b )

        {

               return a+b;

        }

};

 

#include <functional>

 

void main()

{

        int x[5] = { 1, 2, 3, 4, 5 };

        int y[5] = { 1, 2, 3, 4, 5 };

        int z[5];

 

        // x~x+5 에 있는 것과 y에 있는것을 더하여 z에 넣어준다.
       
transform( x, x+5, y, z, plus<int>() );

        copy( z, z+5, ostream_iterator<int>(cout, " ") );

}

Tag |

Trackback Address :: 이 글에는 트랙백을 보낼 수 없습니다