All Questions
Tagged with function-templates sfinae
11 questions
4
votes
1
answer
221
views
Usage of decltype in return type of function template removes error due to exception specification
I saw an answer to a question here. There the author of the answer made use of the fact that
exception specifications do not participate1 in template argument deduction.
In the answer linked above ...
3
votes
1
answer
143
views
Deduct template parameter fail while using if constexpr
I am trying to figure out how the sfinae concept works in C++. But I can't convince the object-type compiler if bool is true or false.
#include <iostream>
class A {
public:
void foo() { std:...
3
votes
2
answers
115
views
How I can specialize template when a method is available?
I wonder how I can have a specialized template for when my type has a specific method. Let's take the following code as an example:
template<typename T, typename... Args>
void foo(T&& ...
3
votes
2
answers
495
views
function template parameter deduction of template parameter vs of default template parameter vs of return type
This is a question about how template deduction works when template parameter used as template parameter vs as default template parameter vs as return type.
1: plain template parameter
As tested using ...
3
votes
6
answers
428
views
Macro for (SFINAEd) template function
#define BINDINGTEMPLATE template<typename T, typename = typename std::enable_if_t < std::is_same_v<typename std::decay_t<T>, int> || std::is_same_v<typename std::decay_t<T>, ...
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
...
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::...
3
votes
1
answer
526
views
C++ friend function template overloading and SFINAE different behaviors in clang++, g++, vc++ (C++14 mode)
So, the following code builds and runs successfully under clang++ (3.8.0), but fails both under g++ (6.3.0) and vc++ (19.10.24903.0). Both g++ and vc++ complain about redefinition of operator&&...
2
votes
1
answer
545
views
limiting specializations using SFINAE, Constraints or Concepts?
The following program runs fine:
struct M; // forward declare so compiler will recognize this type
struct N;
template< typename J > struct B { template< typename U > void Func1(); };
...
12
votes
2
answers
1k
views
How do I enable a function template if a class has a specific member function?
I wrote the following template function, which checks whether an arbitary container contains a specific element:
template<template<class, class...> class container_t, class item_t, class... ...
2
votes
2
answers
2k
views
How to select the right overloaded function template at compile-time?
I'm trying to understand how to select the right overloaded function template at compile-time, but the compiler is giving me a hard time. I can make it work, but I don't understand what is going on. ...