![[STL] std::negate](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FdgWp2f%2FbtsH98nf54P%2FgvkAHxatWB89ybQIpbW3zk%2Fimg.png)
[STL] std::negateC++/STL2024. 6. 23. 22:30
Table of Contents
1. 개요
std::negate는 C++11부터 도입된 표준 라이브러리의 일부이며, 함수형 프로그래밍 스타일을 지원하는 함수 객체(functor)이다. 단항 연산자로 입력된 값을 부정(negation)하는 역할을 한다. 즉, 입력된 값의 부호를 반대로 바꿔준다.
2. 사용 예시
#include <iostream>
#include <functional> // std::negate
int main() {
std::negate<int> neg; // int 타입의 부정 함수 객체를 선언
int x = 10;
int y = neg(x); // -x를 계산하여 y에 할당
std::cout << "x = " << x << ", y = " << y << std::endl;
return 0;
}
2.1. 결과 출력
x = 10, y = -10
3. 참고사항
3.1. 관련 문서
https://en.cppreference.com/w/cpp/utility/functional/negate
std::negate - cppreference.com
template< class T > struct negate; (until C++14) template< class T = void > struct negate; (since C++14) Function object for performing negation. Effectively calls operator- on an instance of type T. [edit] Specializations The standard library provides a s
en.cppreference.com
728x90
@rlozlr :: 얼렁뚱땅 개발자
얼렁뚱땅 주니어 개발자
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!