Questions tagged [function-object]

In object-oriented languages, function object (also known as functor) is a feature that allows objects to be used like if they were ordinary functions.

168 questions
1
vote
3 answers

Function wrapper via (function object) class (variadic) template

C++ I'm trying to implement a function wrapper via a (function object) class (variadic) template. The class has as its only data member a function pointer that is initialized by or assigned the function pointer it is wrapping. The parametrized…
1
vote
1 answer

Do function decorators in python call the decorated function implicitly?

My title could be misleading. my question comes from this code snippet. class myDecorator(object): def __init__(self, f): print "inside myDecorator.__init__()" f() # Prove that function definition has completed def…
eagertoLearn
  • 9,772
  • 23
  • 80
  • 122
1
vote
1 answer

function object with stdout in C++

the program will run correctly if with no cout; why? something wrong with output cache? #include #include #include using namespace std; class fn { public: int i; bool operator()(int,int) { …
tqtifnypmb
  • 11
  • 3
1
vote
4 answers

Where do I define Predicates and Function Objects?

My question is of a purely organisational nature and hence I realize potential answers may be subjective in nature. After years of working with C#, I've finally returned to C++ and am struggling with getting used to how to properly organise the…
Renegade Vile
  • 157
  • 10
1
vote
2 answers

Function objects in Haskell compile error

I'm trying to create a class Func which represents a function, and then a data type Dot which composes functions. Below is my attempt, but I'm getting compile errors: {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FunctionalDependencies #-} {-#…
Clinton
  • 22,361
  • 15
  • 67
  • 163
1
vote
1 answer

javascript augmented prototype and chain

I don't understand why if I add a property or function to a prototype of an existing function object that property or function is not recognized as belonging to the object. Example: var a = function() {}; a.prototype.c = function() {/* code…
cubob
  • 61
  • 1
  • 8
1
vote
2 answers

Parsing ambiguity in a call to a temporary function object

I suspect that in the code below, a call to a temporary function object with both a constructor argument and a function call operator argument is somehow ambiguous due to a most-vexing-parse issue. #include class Fun { public: …
TemplateRex
  • 69,038
  • 19
  • 164
  • 304
1
vote
2 answers

Is the classname() equivalent to a class object?

I know this might be a stupid question but I am not sure how to describe it properly. When I try to call std::transform function for example, template < class InputIterator, class OutputIterator, class UnaryOperator > OutputIterator transform (…
SJinxin
  • 75
  • 7
0
votes
1 answer

Dropdown box representing a method call on a string

I have a dropdown box where the user can select a method to check whether a certain string either equals or endswith another string. I would think to use function pointers/objects as the dropdown box model and call the one currently selected, but…
Kawu
  • 13,647
  • 34
  • 123
  • 195
0
votes
2 answers

Is there an objective reason why the explicitly instantiated std::less, std::greater and similar offer no conversion to function pointer?

Stateless lambdas can be converted to function pointers, e.g. this is valid, using Fun = bool(*)(int, int); constexpr auto less = [](int a, int b){ return a < b; }; Fun f{less}; but objects like std::less{} can't. I do understand why…
Enlico
  • 23,259
  • 6
  • 48
  • 102
0
votes
0 answers

Problems with std::bind and std::placeholder

I'm trying to bind a function object (addWords) with two parameters (string and unsigned) but the compiler doesn't seem to like the std::placeholder. I tried also without std::bind, calling the operator() with a std::placeholder before the for_each.…
0
votes
1 answer

Execution speed of code with `function` object as compared to using template functions

I know that std::function is implemented with the type erasure idiom. Type erasure is a handy technique, but as a drawback it needs to store on the heap a register (some kind of array) of the underlying objects. Hence when creating or copying a…
Giogre
  • 1,444
  • 7
  • 19
0
votes
0 answers

Attempting to use global variable in javascript Function object

Putting this at the top of my post for a little extra clarity: The overall goal here is to build a feature for dynamic banners where you can input some custom javascript animation code through a dynamic data feed in the form of a google sheet. My…
tganyan
  • 603
  • 3
  • 9
  • 23
0
votes
1 answer

Does Boost (or another library) offer a way to lift the name of a "constructor-less" class into a function object that uses aggregate initialization?

This is kind of a follow up to this question, where I asked how I could tersely turn a template and/or overloaded function into a function object. The accepted answer was you can't do without macro, which is correct. Then I found that such a macro…
Enlico
  • 23,259
  • 6
  • 48
  • 102
0
votes
1 answer

Add index signature to a function in .d.ts

I want to overwrite npm library typing to add index signature to a function. Let's say the function does nothing spectacular: export function foo(input) { return Number(input); } It has a typing in .d.ts file: export default function foo(input:…
Buszmen
  • 1,978
  • 18
  • 25