An unary function is a function that takes simply one argument. Each unary operator may also be considered an unary function.
Questions tagged [unary-function]
23 questions
19
votes
2 answers
Why have unary_function, binary_function been removed from C++11?
I found that binary_function is removed from C++11. I am wondering why.
C++98:
template struct less : binary_function {
bool operator() (const T& x, const T& y) const {return x struct less {
…

camino
- 10,085
- 20
- 64
- 115
7
votes
1 answer
Is There a Indirection Functor?
I'm looking for a unary functor which will dereference it's argument and return the result. Of course I can write one, it just seemed like something should already exist.
So given the code:
const auto vals = { 0, 1, 2, 3 };
vector…

Jonathan Mee
- 37,899
- 23
- 129
- 288
4
votes
1 answer
boost program-options uses deprecated feature
I have boost-program-options version 1.78 installed via vcpkg. When I compile with clang++ and -std=c++20 I get the following errors. This doesn't happen when I compile with g++. According to this this std::unary_function is deprecated as of…

David Carpenter
- 1,389
- 2
- 16
- 29
4
votes
1 answer
Passing a function object: Error
What's wrong with the following little program that passes a function object?
#include
#include
void foo(const std::unary_function& fct) {
const std::string str = "test";
fct(str); //…

Frank
- 64,140
- 93
- 237
- 324
3
votes
1 answer
question about C pointer on boolean value,
int bar(int *arr, size_t n)
{
int sum = 0, i;
for (i = n; i > 0; i--)
{
sum += !arr[i - 1];
}
return ~sum + 1;
}
I have come across this code but don't quite understand sum += !arr[i - 1];: what is the effect of !(NOT)…

Nigel
- 161
- 12
3
votes
1 answer
Is it possible to pass a literal value to a lambda unary predicate in C++?
Given the following code that does a reverse lookup on a map:
map m = {{'a', 1}, {'b', 2}, {'c', 3}, {'d', 4}, {'e', 5}};
int findVal = 3;
Pair v = *find_if(m.begin(), m.end(), [findVal](const Pair & p) {
return…

WXB13
- 1,046
- 3
- 11
- 17
2
votes
1 answer
Apply a unary transformer to a linkedlist
I've been working on a practice problem. The idea is that I'm supposed to take a linked list, then apply a unary transformer to the list, and return the modified list. I'm not applying a specific change, just process and return a linked list. Here's…

009
- 83
- 1
- 1
- 11
1
vote
2 answers
Int++ operator isn't increasing the int the first time it's ran
Basically the goal of the program is to have the user input a number, increase is 3 times, then decrease it 3 times using unary operators. The issue is that when it's ran, the first "number is now ___" line ends up just showing the same number the…
user11287089
1
vote
3 answers
What is the use of the hyphen before a function in SQL (SQLServer)
I would like to find out what the logic behind the SQL Syntax is when including a hyphen before calling a SQL function enclosed in parentheses.
Here is the SQL:
IF (@StartDate > @EndDate)
BEGIN
SET @EndDate = @StartDate
SET @StartDate =…

Chanté Ana-May King
- 63
- 8
1
vote
4 answers
HashMap in Unary Functional Interface with Lambda in Java 8
I'm studying for Java 8 Lambda and Unary Functional Interface. I have a practice assignment about "Function" class using HashMap, which the following steps to do:
Create a variable of type Function that receives a Set and creates a…

Giacomo Brunetta
- 1,409
- 3
- 18
- 38
1
vote
1 answer
Unary Functional Interface with Lambda in Java 8
I'm studying for Java 8 Lambda and Unary Functional Interface. I have a practice assignment about "Function" class, which the following text:
1) Create a class called "FunctionTest" with a main method
2) Create a Function variable and call it as…

Giacomo Brunetta
- 1,409
- 3
- 18
- 38
1
vote
1 answer
Passing an iterarator to a unary predicate with std::find_if
I am trying to find the index, i, of an element of a vector, v, that satisfies: v[i] <= x < v[i + 1], where x is a given arbitrary value. I am trying to use the find_if function, but it appears that find_if passes the value from the iterator and not…

EliSquared
- 1,409
- 5
- 20
- 44
1
vote
1 answer
Clearing std::vector of pointers with std::unary_function
In his "Effective STL" Meyers show how to clean vector of pointers correctly (std::vector::clear deletes only his pointers, and not the memory they occupy).
So he advices before the call to clear use for_each with unary_function which calls object…

olha
- 2,132
- 1
- 18
- 39
0
votes
0 answers
Problem with unary minus, in custom calculator with custom priorities
I tried making custom calculator with priorities - and / being greater then + and *.
It works nearly perfectly in that manner but I come to problem with unary minus. When it removes (), rather then for example from 1 + (-3), removing + and adding…

MerHin
- 1
- 1
0
votes
0 answers
How to best design function that takes an unary predicate
I'm implementing a simple timeout-class which calls a given function when time runs out.
However I'm scratching my head on how to make the function constructor take an unary predicate, e.g. function pointer, std::function, functor or lambda, in the…

glades
- 3,778
- 1
- 12
- 34