transform使用详解
来源:互联网 发布:淘宝详情页怎么优化 编辑:程序博客网 时间:2024/05/22 12:06
文件原型及可能的实现:
版本一:
template<class InputIt, class OutputIt, class UnaryOperation>OutputIt transform(InputIt first1, InputIt last1, OutputIt d_first, UnaryOperation unary_op){ while (first1 != last1) { *d_first++ = unary_op(*first1++); } return d_first;}
对first1
、last1
范围内的元素执行一元操作unary_op
后保存在d_first
开始的位置。
版本二:
template<class InputIt1, class InputIt2, class OutputIt, class BinaryOperation>OutputIt transform(InputIt1 first1, InputIt1 last1, InputIt2 first2, OutputIt d_first, BinaryOperation binary_op){ while (first1 != last1) { *d_first++ = binary_op(*first1++, *first2++); } return d_first;}
对first1
、last1
及first2
二元操作binary_op
后保存在d_first
开始的位置。
从它们的实现也能看出来它们的作用。
示例:
#include <string>#include <ctype.h>#include <algorithm>#include <functional>#include <iostream>int main(){ std::string s("hello"); std::transform(s.begin(), s.end(), s.begin(), ::toupper); std::cout << s;}
输出是:
HELLO
示例:
std::string s("hello"); std::string d("kkkkk"); std::transform(s.begin(), s.end(), d.begin(), ::toupper); std::cout << s << std::endl; std::cout<<d<<std::endl;
输出是:
helloHELLO
示例:
std::string s("hello"); std::transform(s.begin(), s.end(), s.begin()+2, ::toupper); std::cout << s << std::endl;
输出是:
heHEH
最后附上源码
// transformtemplate <class _InputIter, class _OutputIter, class _UnaryOperation>_OutputIter transform(_InputIter __first, _InputIter __last, _OutputIter __result, _UnaryOperation __opr) { __STL_REQUIRES(_InputIter, _InputIterator); __STL_REQUIRES(_OutputIter, _OutputIterator); for ( ; __first != __last; ++__first, ++__result) *__result = __opr(*__first); return __result;}template <class _InputIter1, class _InputIter2, class _OutputIter, class _BinaryOperation>_OutputIter transform(_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2, _OutputIter __result, _BinaryOperation __binary_op) { __STL_REQUIRES(_InputIter1, _InputIterator); __STL_REQUIRES(_InputIter2, _InputIterator); __STL_REQUIRES(_OutputIter, _OutputIterator); for ( ; __first1 != __last1; ++__first1, ++__first2, ++__result) *__result = __binary_op(*__first1, *__first2); return __result;}
0 0
- transform使用详解
- ViewPager Transform 使用详解
- ViewPager Transform 使用详解
- transform详解
- Transform详解
- transform使用
- transform使用
- 使用css3 transform 属性来变换背景图方法步骤详解
- css3之transform详解
- CSS3详解:transform
- [HTML5&CSS3]Transform详解
- View Transform 详解
- CSS3详解:transform
- CSS3详解:transform
- css transform 详解
- CGAffine Transform 参数详解
- CSS3 Transform详解
- CSS3中的transform详解
- DWR搭建以及使用教程
- Lua笔记:帧动画及CocosStudio动画应用
- Java多线程基础(二)定时器类:Timer类和TimerTask类
- drupal 简介
- 黑马程序员_JAVA IO 流 基本概述
- transform使用详解
- 一个网络游戏程序员员的棋牌开发之路
- 查看linux 下已经安装的软件包信息
- 通用权限系统设计实现
- 移动端尺寸基础知识
- 4.22
- HDU1870
- mysql 控制台简单操作
- 凡客:成于营销,败于营销