Tags
- Interaction developer
- emplace_back
- Android
- Android/iOS Developer
- postman csv
- 프런트엔드
- postman session
- 우수한 프런트 개발자
- 좋은 개발자
- LSL_Script
- 다빈치 리졸브
- Unity
- Java
- postman html parse
- C++
- postman
- web developer
- solidity
- postman tests
- postman excel
- Front-end developer
- postman automations
- UI/UX Engineer
- oracle
- postman collection
- postman collection variables
- MFC
- c#
- Intellij
- postman pre-request
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Archives
- Today
- Total
david's daily developer note
[C++] std::transform 본문
728x90
std::transform 함수는 개별 요소들에 주어진 함수 동작을 적용시킨다.
즉, 여러 요소(elements)로 구성된 자료형에서 각 요소에 주어진 함수를 적용하여 값을 변경하며,
새로운 저장공간에 저장하거나, 기존 값을 변경하는 역할을 한다.
복잡하게 for문을 사용하지 않고 코드가 간결해질 수 있다!
문자열 (std::string)의 각 문자를 대문자로 변환
문자열 lower의 시작 문자부터 마지막 문자까지 ::toupper함수를 적용하여 대문자로 변환하는 예제
string lower = "orange";
std::transform(lower.begin(), lower.end(), lower.begin(), ::toupper);
std::cout << lower << std::endl;
정수형 벡터 요소에 +1하기
from 벡터의 시작 요소부터 마지막 요소까지 주어진 람다 함수를 적용하고, to 벡터에 저장하는 예제
std::vector<int> from = {1,2,3,4,5};
std::vector<int> to;
to.resize(5);
std::transform(from.begin(), from.end(), to.begin(),[](int n) {return n + 1; });
for (int val : to)
std::cout << val << std::endl;
두개의 정수형 벡터 요소를 더하기
foo 벡터와 bar 벡터의 시작 요소부터, 마지막 요소까지 각 순서에 맞는 요소끼리 합하고, foo 함수에 저장하는 예제
std::vector<int> foo = { 1,2,3,4,5 };
std::vector<int> bar = { 10,20,30,40,50 };
std::transform(foo.begin(), foo.end(), bar.begin(), foo.begin(), std::plus<int>());
for (int val : foo)
std::cout << val << std::endl;
728x90
'[Develop] Native > C++ , C' 카테고리의 다른 글
[C++] 최대값, 최소값 (0) | 2022.11.06 |
---|---|
[C,C++] East Const (0) | 2018.12.20 |
[C,C++] Magic Static (Dynamic Initialization and Destruction with Concurrency) (0) | 2018.12.19 |
[C,C++] __func__ (0) | 2018.12.19 |
[C,C++] copy constructor (0) | 2018.06.26 |