Skip to main content

All Questions

Filter by
Sorted by
Tagged with
0 votes
3 answers
148 views

Why I need default sum function, for a variadic template sum?

I want to calculate the sum of any number of arguments given to function sum. Assuming that integers given to the function will satisfy operator+. If I comment out the function sum() (the one having ...
Aditya Garg's user avatar
2 votes
1 answer
172 views

Point of Instantiation for function templates

I am learning about templates in C++. In particular, i read about POIs. So i am trying out(by reading and writing) different examples. One such example which is not clear to me is given below: ...
user12002570's user avatar
1 vote
2 answers
408 views

Calling undeclared function template from inside another function template

I am learning about templates in C++ and so trying out different examples. One such example whose output i am unable to understand is given below: template<typename T> void func(T p) { g<T>...
user12002570's user avatar
2 votes
2 answers
514 views

Unresolved overloaded function type in gcc

I am trying to pass a function template as an argument to another function as seen in the example below. #include <iostream> template <typename T> decltype(auto) foo(T t) { return ...
Petok Lorand's user avatar
2 votes
1 answer
57 views

Stringify a recursive `std::vector<std::vector<...>>` without using partial template function specialization

I seek (for example) to stringify a vector of vectors of ... (with arbitrarily deep nesting). I tried the following: #include <iostream> #include <sstream> #include <vector> ...
Museful's user avatar
  • 6,949
1 vote
2 answers
199 views

Function template specialization with const ref arguments

The following code compiles fine. #include <iostream> struct rgb8{ uint8_t r() const {return 0;}; }; template<typename L, typename P> L pixelToLevel(P p) { return static_cast<...
Museful's user avatar
  • 6,949
2 votes
2 answers
276 views

Forwarding wrapper using `std::enable_if` failing

I am trying to create a forwarding wrapper function which times the call of a function in c++14. There are 2 types I need to deal with, one is timing a function which doesn't return a value, and ...
Sridhar Thiagarajan's user avatar
4 votes
1 answer
2k views

Why is my function template specialization rejected by VS2017 and not by VS2015?

I have a trait class that associates types to integer values. struct traits { private: template<int ID> struct type_impl {}; template<> struct type_impl<1> { using type = ...
Yohann Bénédic's user avatar
10 votes
1 answer
463 views

SFINAE : Delete a function with the same prototype

I wonder what is the difference between this code that works : #include <type_traits> #include <iostream> template<typename T> using is_ref = std::enable_if_t<std::...
Antoine Morrier's user avatar
2 votes
2 answers
209 views

function overloading with std::function and generic lambdas: std::string preferred over int

When trying to compiling this, suprisingly, it gives an error because the auto parameter of the lambda function has been resolved to std::string, and the compiler doesn't know how to convert std::...
ABu's user avatar
  • 12.2k
8 votes
1 answer
1k views

Passing (partially) templated template function as std::function(or function pointer)

#include <vector> #include <functional> template<class F> class Foo { public: template <class T> void std_function(std::function<F(std::vector<T>)> functor)...
suhdonghwi's user avatar
  • 1,035
24 votes
4 answers
15k views

How do you deduce the size of a std::array?

In the following code: template<size_t N> int b(int q, const std::array<int, N>& types) { int r = q; for (int t : types) { r = r + t; } return r; } int ...
paulm's user avatar
  • 5,842
5 votes
3 answers
3k views

Function parameter type using decltype

Note: the example provided in this question is not production code and has no sense at all. It is just there to illustrate my problem. I was testing the possibilities of decltype, especially if it is ...
nshct's user avatar
  • 1,217
1 vote
3 answers
169 views

Disallow function template instantiation with iterator parameter

I have a function template which takes a templated parameter: template <class R> RefT<R> make_ref(R& res) { return RefT<R>(&res); } I either want to prevent R from ...
Lynden Shields's user avatar