
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
negate function in C++ STL
Negate function is used to negate the given values such that to change the sign of the values. It changes the negative values to positive and vice-versa.
Function prototype:
function transform(a_begin, a_end, a1_begin, negate()): a_begin = lower bound of the array. a_end = upper bound of the array. a1_end = Lower bound of the second modified array. negate() = to negate the values of the array.
Example Code
#include <algorithm> #include <functional> #include <iostream> using namespace std; int main() { int a[] = { 4,6,7, -10, -20, -30 }; transform(a, a + 6, a, negate<int>()); for (int i = 0; i < 6; i++) cout << a[i] << ' '; return 0; }
Output
-4 -6 -7 10 20 30
- Related Articles
- How to negate a predicate function in JavaScript?
- sinh() function in C++ STL
- cosh() function in C++ STL
- atanh() function in C++ STL
- tanh() function in C++ STL
- acosh() function in C++ STL
- asinh() function in C++ STL
- acos() function in C++ STL
- atan2() function in C++ STL
- iswalnum() function in C++ STL
- iswalpha() function in C++ STL
- lldiv() function in C++ STL
- iswpunct() function in C++ STL
- iswspace() function in C++ STL
- iswupper() function in C++ STL

Advertisements