alones.kr/blog로 사이트 이전했습니다. 관련 공지

Alones world : Location : Tag : GuestBooks : Admin : New Article : Alones Wiki : Joinc TeamBlog
Alones world 블로그에 오신것을 환영해요^^
gidaeyeo@gmail.com
57
255
365186

Add to Google Reader or Homepage

 Subscribe in a reader

현재 접속 자 수
hit counters
------------
Recently Popular Posts
------------

  • initial version: 2007.06.15

목차

1 Introduction
2 Signature
3 Inside
4 Usgae
5 References
6 See Alos

1 Introduction #

STL의 Container (std::list, std::vector, etc)들의 모든 elements를 변환할 때 사용한다 (의미하는 그대로). algorithm에 포함된 것 답게 unary (단항) operator나 binary (이항) operator를 parameter로 받아서 처리해준다. 즉, std::vector의 모든 elements를 1씩 증가 시켜주거나 prefix로 특정 문자를 붙이는 경우 사용할 수 있을 것이다.

2 Signature #


다음과 같이 두 가지 원형을 제공한다.

template < class InputIterator, 
class OutputIterator, class UnaryOperator >
OutputIterator transform
( InputIterator first1, InputIterator last1,
OutputIterator result, UnaryOperator op ); template < class InputIterator1, class InputIterator2, class OutputIterator, class BinaryOperator > OutputIterator transform
( InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, OutputIterator result, BinaryOperator binary_op );
//

첫 번째 것은 단항 연산자를 이용해서 입력으로 들어오는 container의 처음과 끝 iterator를 처리해주고 결과를 output conatiner의 iterator에서 차례로 넣어 준다. 두 번째 것은 이항 연산자를 이용해서 첫 번째 container (first1 ~ last1)와 두 번째 container의 시작 (frist2) 부터를 처리해서 output containter의 iterator에 차례로 넣어 준다.

3 Inside #


Visual C++ 6.0은 위 두 개 원형을 다음과 같이 구현해두었다. 설명 그대로이다.

// TEMPLATE FUNCTION transform WITH UNARY OP
template<class _II, class _OI, class _Uop> inline
        _OI transform(_II _F, _II _L, _OI _X, _Uop _U)
        {for (; _F != _L; ++_F, ++_X)
                *_X = _U(*_F);
        return (_X); }
// TEMPLATE FUNCTION transform WITH BINARY OP
template<class _II1, class _II2, class _OI, class _Bop> inline
        _OI transform(_II1 _F1, _II1 _L1, _II2 _F2, _OI _X,
_Bop _B)
{for (; _F1 != _L1; ++_F1, ++_F2, ++_X) *_X = _B(*_F1, *_F2); return (_X); }
//

4 Usgae #

다음의 간단한 예는 10,20,30,40,50이 elements로 들어있는 vector를 unary operator를 이용해서 1씩 증가시키고 binary operator를 이용해서 최초 vector와 1씩 증가한 vector를 더하는 예이다.

#include <iostream>
#include <algorithm>
#include <vector>

// 1씩 증가 시키는 unary operator
int op_increase (int i)
{
        return ++i;
}

// 두 수를 더하는 binary operator
int op_sum (int i, int j)
{
        return i+j;
}

int main ()
{
  std::vector<int> first;
  std::vector<int> second;
  std::vector<int>::iterator it;

  // 첫 번째 container
  // 10, 20, 30, 40, 50
  for (int i=1; i<6; i++)
          first.push_back (i*10);

  // 두 번째 container size 할당
  second.resize(first.size());

  // usage 1
  // 첫 번째 container의 elements를 
  // op_increase unary operator를 이용해서 
  // 1씩 증가
  // 결과 11, 21, 31, 41, 51
  std::transform (first.begin(), first.end(),
                                  second.begin(),
                                  op_increase);

  // usage 2
  // 첫 번째 container의 elements와
  // usgae 1의 결과 container를
  // op_sum인 binary operator를 이용해서 
  // 더함
  // 결과 21, 41, 61, 81, 101
  std::transform (first.begin(), first.end(),
                              second.begin(),
                              first.begin(),
                              op_sum);

  // 결과 출력
  std:: cout << "first contains:";
  for (it=first.begin(); it!=first.end(); ++it)
    std::cout << " " << *it;

  std::cout << std::endl;
  return 0;
}

//


6 See Alos #



※ 최신 내용은 아래 wiki에서 확인할 수 있습니다.
 in my wiki: http://alones.byus.net/moniwiki/wiki.php/transform?action=show

크리에이티브 커먼즈 라이센스
Creative Commons License
Trackback 1 : Comment 10
http://alones.byus.net/tt/trackback/673
From. cheap clopidogrel 2008/05/22 22:26Delete / Modify
cheap clopidogrel
Trackback
From. BlogIcon raven riley nude video 2008/03/13 06:31Delete / ModifyReply
이 위치는 유익한뿐 아니라 재미있는다!
From. BlogIcon 2006 mustang mach 1 2008/03/13 07:11Delete / ModifyReply
너는 아주 좋은 보는 위치가 있는다!
From. BlogIcon bag big glad 2008/03/13 07:59Delete / ModifyReply
너는 우수한 위치가 있는다!
From. BlogIcon fucking man woman 2008/03/13 08:43Delete / ModifyReply
너는 아주 좋은 보는 위치가 있는다!
From. BlogIcon florida community colleges 2008/03/14 03:49Delete / ModifyReply
나의 친구는 너의 위치의 현재 팬이 되었다!
From. BlogIcon ads sex woman 2008/03/14 04:36Delete / ModifyReply
좋은 위치! 너를 감사하십시요.
From. BlogIcon airport parking spokane 2008/03/14 04:37Delete / ModifyReply
너는 우수한 위치가 있는다!
From. BlogIcon milf video favourites 2008/05/23 04:16Delete / ModifyReply
위치에 그것을 중대한 일은 좋아했다!
From. BlogIcon free poker software strip 2008/05/24 00:35Delete / ModifyReply
걸출한 블로그!
From. BlogIcon diviant art naruto xxx 2008/05/24 00:40Delete / ModifyReply
너의 방문한 위치를 즐기는!

Alones world를 alones.... (15)
나는 잘 모르지만, 유시... (19)
블로그 코리아의 회원가... (7)
MS 윈도우 클라이언트... (2)
비누넷의 구글 크롤링으... (5)