Questions tagged [function-template]
12 questions
12
votes
2 answers
Is there a generic way to adapt a function template to be a polymorphic function object?
I have some function templates, for example
template
void foo(T);
template
void bar(T);
// others
and I need to pass each one to an algorithm that will call it with various types, e.g.
template
void…

HighCommander4
- 50,428
- 24
- 122
- 194
9
votes
1 answer
Is there such a thing as a function template template parameter?
So I know C++ has a feature called "template template parameters", where you can pass a class template as a template parameter. For example:
template
class vector { ... };
template class container> // this is a…

HighCommander4
- 50,428
- 24
- 122
- 194
2
votes
1 answer
C++ error: default template arguments may not be used in function template
I am trying to understand what the value = T() means and how to fix it. Also the function is a constructor for a class.
template
Accumulator::Accumulator(const T& value = T())
{
total = value;
}
This does not compile the…

John
- 23
- 5
2
votes
1 answer
Simulating function templates in Java
I'm trying to simulate something analogous to a function template in Java, in the sense that I have something like the following:
public interface MyFunctionTemplate {
void doSomething(T thing);
}
public class MyIntegerFunctionTemplate…

Kelvin Chung
- 1,327
- 1
- 11
- 23
0
votes
2 answers
How/where are template-functions allocated?
Is the following use of the template-function fCompare() correct?
//header
template class SomeClass
{
typedef int (*COMPAREFUNC)(_T*,_T*);
COMPAREFUNC Compare;
public:
void SetCompareFunction(COMPAREFUNC pfC) { Compare=pfC;…

slashmais
- 7,069
- 9
- 54
- 80
0
votes
0 answers
Template of wrapper for variadic template functions
I am implementing a template for a wrapper, as in :
C++ function call wrapper with function as template argument
Wrap a function pointer in C++ with variadic template
The wrapper taken from the links above is :
template

Frank Jefferson
- 77
- 5
0
votes
1 answer
function template as a function argument
I want to implement a function which acts as MATLAB sort().
I defined a structure and a function template in a head file, as below.
template struct SORT_DATA
{
T_val value; //
int…

user18441
- 203
- 2
- 11
0
votes
1 answer
Template function with chrono::duration parameter and returning result of chrono::duration::count
I'm trying to write a function that allows the user to specify a chrono::duration like chrono::seconds and return the result of chrono::duration::count.
I'm able to do this using the following template function:
template

user3731622
- 4,844
- 8
- 45
- 84
0
votes
0 answers
gcc:g++ being bureaucratic with template template friends
In header view.h:
template class V>
void Operate(S c, const V& vx);
template class U>
class ViewBase
{
template class V>
friend void Operate(S c, const…

skm
- 329
- 2
- 9
0
votes
2 answers
getting result from a specific base in a templated class with variable number of templated arguments
I am trying to implement a templated class like below.
struct Ciccio2 : public T1, public T2, public T3, public T4
{
template
int get(const string& s) const
{
return TR::operator()(s);
}
};
All…

Abruzzo Forte e Gentile
- 14,423
- 28
- 99
- 173
0
votes
0 answers
identity wrapper in an overload function signature disables overload
I hava overloaded stream operator << for a new template type X and that works. But if I wrap that type with the identity function identity>::type the code breaks.
I tried gcc 4.6.2 / gcc 4.8.1 / clang 3.3
Any hint?
#include…

Patrick Fromberg
- 1,313
- 11
- 37
0
votes
1 answer
Using Pointer to class with v8 FunctionTemplate gives error
My Model is as follows
using namespace v8;
using namespace node;
class A {
private:
//something
public:
//something
}
class X {
private:
A* a;
public:
X() {
a = new A();
}
Handle myfunc(const…

Boopathi Rajaa
- 4,659
- 2
- 31
- 53