Questions tagged [template-argument-deduction]

Template argument deduction is a compiler attempt to deduce template arguments when some are omitted.

692 questions
0
votes
2 answers

Integral types messing up with sizeof(T)

class Foo { public: Foo(const void* data) : m_dataPtr(data) {} template const T Get() { const T* readPoint = static_cast(m_dataPtr); m_dataPtr = (const char *) m_dataPtr + sizeof(T); return…
0
votes
3 answers

C++11, type deduction of derived class in static method

Minimal example: class Task { public: template static T* make(Args... args) { return new T(args...); } } template class MyTask : public Task { public: MyTask(A a, B b, C…
mikepurvis
  • 1,568
  • 2
  • 19
  • 28
0
votes
1 answer

Template argument deduction fails on lambda using tuple

I'm trying to make a query function that lets me query an STL container for certain element characteristics, and then return the result set. It's really just syntactic sugar around normal STL operations (specifically, copy_if and a…
0
votes
2 answers

function template argument deduction in a class

I have always thought that function template argument deduction can work only for pure function like below and not for classes. template T foo(T2 a, T3 b) { T o; //..do something return o; } Today Just by…
Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173
0
votes
2 answers

Partial template specialization by overloading

I created a simple round template function with an extra template argument that defines the type the rounded value needs to be casted to before returning. template T round(U val) { T result; if (val >= 0) …
0
votes
2 answers

Resolving ambiguous call in template argument deduction

A typical function template signature: template T fn(Iterator first, Iterator last, T init) { T result; // ... return result; } The problem is, when I call it like this: std::vector
Charles Pehlivanian
  • 2,083
  • 17
  • 25
0
votes
0 answers

Is template template parametrs supported for function supported in new C++ standards?

I found the following statement in the book C++ Template: The complete Guide: Template template parameters for function templates are not allowed. But he following piece of code compiles and run for me. template< typename T, template
0
votes
3 answers

Function template cannot deduce type if types T and U are the same

This question stems from an answer I received yesterday. For the following function, I am getting the error couldn't deduce template parameter ‘V’ if both T and U are std::complex. If T and U are different, the function compiles and works as…
OSE
  • 986
  • 2
  • 13
  • 19
0
votes
4 answers

Can I write something that uses type deduction as in make_tuple?

I can either write make_tuple(1,true) or write make_tuple(1,true) and the compiler will deduce it's types. Is this ability available for code I write or is it somehow built into the compiler to which I can't access?
Fred Finkle
  • 1,947
  • 3
  • 18
  • 21
-1
votes
1 answer

variadic template argument deduction, cannot match struct in argument

I can't work this out. I have a template class integer that has in its template parameter its value, and I want to add together n integers of this class. I can successfully get the int value from the class in the base case, but it fails…
-1
votes
1 answer

Determining the type of the template parameter method argument

There are many IEnumXXXX type COM interfaces that have a pure virtual method Next, like this: IEnumString : IUnknown { ... virtual HRESULT Next(ULONG, LPOLESTR*, ULONG*) = 0; ... }; IEnumGUID : IUnknown { ... virtual HRESULT Next(ULONG, GUID*,…
-1
votes
2 answers

Template argument deduction Doesn't Work for Function Template

I am trying to understand how template argument deduction works in C++. And so writing out different examples. One such example which doesn't work and i can't understand why is given below: #include template void func…
Jason
  • 36,170
  • 5
  • 26
  • 60
-1
votes
2 answers

Template deduction guide fails with 'too many initializers' error

I was reading on template deduction then tried to create one. as follows:- #include #include using namespace std; template struct deducted{ }; //Deduction guide template
-2
votes
1 answer

C++ How to create a class template that allows no template arguments

I apologize if my title is confusing. What I'm trying to do is create a class template implementing the std::map from scratch. What I want to achieve is to not use specific data types in the template arguments. Please see the code below: #include…
Mr George
  • 39
  • 7
-2
votes
2 answers

Any way to define a "doubling" operator?

I have a class that represents a quantity that can only take on integer or half-integer values, and so stores its value internally as an integer that is twice the value. That is: a value of 0.5 is stored as 1, 1 as 2, 1.5 as 3, etc. Let's call it…
1 2 3
46
47