sfinae Questions
2
Solved
Let's create currying function.
template <typename TFunc, typename TArg>
class CurryT
{
public:
CurryT(const TFunc &func, const TArg &arg)
: func(func), arg(arg )
{}
template <...
Chane asked 9/5, 2022 at 13:53
1
Solved
I'm curious about the definition of std::is_invocable_r and how it interacts with non-moveable types. Its libc++ implementation under clang in C++20 mode seems to be wrong based on my understanding...
Salpiglossis asked 9/5, 2022 at 1:5
10
Solved
template<class T>
struct is_iterator
{
static const bool value = ??? // What to write ???
};
int main()
{
assert(false == is_iterator<int>::value);
assert(true == is_iterator<vec...
0
Suppose we have a current class:
template<typename T>
struct Inheriter : public T {};
Note that its instantiation would be well-formed only if T is a class/struct that is not declared as fin...
Capricorn asked 13/4, 2022 at 15:41
3
Solved
I want to write a type trait which uses SFINAE to check a type for the existence of a subscript expression. My initial attempt below seems to work when the subscript expression is possible but does...
Somatoplasm asked 9/7, 2015 at 0:0
1
Solved
I wanted to activate a class with parameter packs when all types in the parameter pack is distinct. I wrote a small helper function like this that works with no problem:
template<typename T, typ...
3
Solved
I watched Walter Brown's talk at Cppcon14 about modern template programming (Part I, Part II) where he presented his void_t SFINAE technique.
Example:
Given a simple variable template that evaluate...
0
I produced a code that has implementation divergence and I want to know which compiler is right and why, or which part of the standard allows those compiler to differ:
#include <type_traits>
...
Lalita asked 2/1, 2022 at 4:37
1
Solved
Setup
I asked a question yesterday about template method overloading and resolving issues using type traits. I received some excellent answers, and they led me to a solution. And that solution led ...
Bootery asked 14/12, 2021 at 14:32
3
Solved
I'm trying to specialize a struct template for multiple types at once using
SFINAE. I know that something like the following works:
#include <iostream>
template <typename T, typename Ena...
Nereus asked 9/8, 2016 at 20:23
4
Solved
I was thinking that I could test (with C++14) if a class contained a type, I could do this:
#include <type_traits>
struct X {
using some_type = int;
};
struct Y {};
template <typename T...
Marenmarena asked 10/11, 2021 at 17:30
8
Solved
In this answer I define a template based on the type's is_arithmetic property:
template<typename T> enable_if_t<is_arithmetic<T>::value, string> stringify(T t){
return to_string...
Urolith asked 12/5, 2015 at 11:45
1
Solved
I wrote an is_incrementable trait like this:
#include <type_traits>
template <typename T, typename = void>
struct is_incrementable : std::false_type {};
template <typename T>
s...
Jura asked 24/6, 2018 at 16:28
34
Solved
Is it possible to write a template that changes behavior depending on if a certain member function is defined on a class?
Here's a simple example of what I would want to write:
template<class ...
Mesic asked 2/11, 2008 at 20:10
11
Is it possible to write a type trait whose value is true for all common STL structures (e.g., vector, set, map, ...)?
To get started, I'd like to write a type trait that is true for a vector and f...
1
Solved
I have a SFINAE template version of is_same for comparing template template arguments.
It generally works as expected on both templates with fixed and variadic number of template parameters:
namesp...
Lunitidal asked 29/9, 2021 at 22:22
3
Solved
I was reading this prehistoric metaprogam example to detect whether a class supports member find. (or any other member).
template<typename T>
class DetectFind
{
struct Fallback { int find; }...
Swart asked 31/8, 2021 at 9:40
3
So with SFINAE and c++11, it is possible to implement two different template functions based on whether one of the template parameters can be substituted.
For example
struct Boo{
void saySomethi...
Hiramhirasuna asked 28/3, 2015 at 15:36
4
Solved
I want to check if two types are of the same template. As an example I want the following snippet of code to return true because both objects are vectors despite the inner elements being of differe...
Gabriellagabrielle asked 28/3, 2019 at 10:14
3
Solved
There are a number of answered questions about checking whether a member function exists: for example,
Is it possible to write a template to check for a function's existence?
But this method ...
10
Solved
I want to get into more template meta-programming. I know that SFINAE stands for "substitution failure is not an error." But can someone show me a good use for SFINAE?
Miche asked 11/6, 2009 at 18:25
2
Solved
I am implementing something very similar to std::vector but uses array on the stack instead of memory allocation.
The d-tor calls a function that uses SFINAE.
If value_type is POD the function h...
2
Solved
I am looking for a way to use SFINAE to implement some function, that must be available only to some containers:
vector, list, array (set is there below only as a test)
Build upon this answer, I tr...
Consols asked 23/6, 2021 at 9:30
4
The base components of my hobby library has to work with C++98 and C++11 compilers. To learn and to enjoy myself I created the C++98 implementations of several type support functionality (like enab...
Skintight asked 5/11, 2016 at 15:25
1
Solved
Given a struct S:
struct S {
bool a : 1;
bool b : 1;
};
How to determine that S::a and S::b are bit-fields at compile time?
I was trying to come up a macro like IsBitField(S, a) but had hard tim...
Ism asked 4/4, 2021 at 20:19
© 2022 - 2024 — McMap. All rights reserved.