sfinae Questions
1
Solved
I am just trying my hands on SFINAE using std::enable_if in C++. I thought i understood the theory part until i couldn't get the following piece of code to compile. Adding to this confusion is the ...
Congo asked 16/9, 2019 at 21:39
1
Solved
I think the following code is well-formed:
template< typename T >
using IsSigned = std::enable_if_t< std::is_signed_v< T > >;
template< typename T, IsSigned< T >... >...
Embrocation asked 4/9, 2019 at 7:22
3
Solved
Under certain conditions, I'd like to SFINAE away the copy constructor and copy assignment operator of a class template. But if I do so, a default copy constructor and a default assignment operator...
Farber asked 3/4, 2015 at 10:7
1
Solved
I want to pick a specialization of a template when a certain type is defined.
I still cannot wrap my head around SFINAE :(. I might be close or I might be completely off. I tried different things...
1
Solved
What is the differences between these classes? Specifically, these member functions with enable_if.
/// Alias of std::enable_if...
template <bool B, typename T = void>
using Enable_if = typen...
2
Solved
#include <type_traits>
class Base {
public:
virtual bool f() {
return true;
}
};
template<typename T>
class Derived : public Base {
std::enable_if_t< std::is_copy_constructible...
Ojeda asked 4/8, 2019 at 9:31
3
Solved
I have codes like this:
class Bar {
public:
void print() {
std::cout << "bar\n";
}
};
template<typename T>
class Foo {
public:
template <typename std::enable_if<std::is_ba...
Kevinkevina asked 19/7, 2019 at 3:17
2
Solved
I can not get my head around the following problem. I don't even really know how I could approach it.
Consider this code:
struct fragment_shader {
std::string mPath;
};
struct vertex_shader {
...
1
Solved
I've done some looking around, but was unable to find a solution to my specific problem.
I have the code:
template <typename T>
typename std::enable_if<std::is_arithmetic<T>::value...
1
Solved
I have this minimal expression template library with a multiplication, i.e.
template <typename T, typename U>
struct mul {
const T &v1;
const U &v2;
};
template <typename T, ty...
Smart asked 29/5, 2019 at 12:24
2
Solved
I am attempting to use SFINAE to limit the allowable template parameter types for a class I am writing. Here is a simple contrived example I came up with that I believe illustrates what I would lik...
2
Solved
Why I have to use the default value (::type = 0) in this std::enable_if usage?
I see examples, where it works without it. for example https://foonathan.net/blog/2015/11/30/overload-resolution-4.ht...
2
Solved
I'm working on a custom, template-heavy serialization library with custom serializers. I want to be able to detect and enforce the Serializer concept in my library using SFINAE (I don't have access...
Gaiseric asked 6/5, 2019 at 4:20
1
Solved
I have followed this post: Class template SFINAE
to instantiate the template class conditionally.
That works perfectly for the classes which have only one template parameters, as shown in the link...
3
Solved
Consider the following MCVE
struct A {};
template<class T>
void test(T, T) {
}
template<class T>
class Wrapper {
using type = typename T::type;
};
template<class T>
void test...
Footcloth asked 30/4, 2019 at 12:26
2
Solved
I am trying to write a function such that f<T>(args..) returns the first parameter of type T.
The following program seems to always select the first specialization thus printing 97 (ASCII c...
Neary asked 20/4, 2019 at 16:30
6
Solved
From the cppreference.com article on std::enable_if,
Notes
A common mistake is to declare two function templates that differ only in their default template arguments. This is illegal because de...
Epistasis asked 13/4, 2019 at 16:47
2
Solved
I have a family of functions {f_n} where f_0 is continuous, f_1 is continuously differentiable, $f_{n} \in C^{n}[a,b]$ so on. I have a C++ class which gives a numerical evaluation of f_n via a look...
Vidovik asked 1/3, 2019 at 20:53
1
Solved
I have a function and I need to test whether I can pass an argument of a given type to it. For example:
template<typename T, auto F>
decltype(F(declval<T>{})) foo();
Calling foo<i...
Katlin asked 1/3, 2019 at 15:11
1
Solved
I would like to unify an interface to work with both templated and non-templated types. Is there a way to determine whether a type, such as a class or a function pointer is depends on a template pa...
2
Solved
Below SFINAE code with variadic templates compiles nicely using clang 3.7.1, C++14:
#include <array>
#include <iostream>
#include <vector>
#include <cstdint>
enum class Ba...
Bots asked 12/4, 2016 at 8:48
3
Solved
I'm trying to find a way to simply check if a method of a given name exists in a c++ class using c++11 features, but without(!) checking the signature.
I was unable to find anything without the si...
1
Solved
One of my container's constructors default-constructs an allocator as a default parameter value:
template<class T, class Allocator>
struct my_container
{
my_container(int n, Allocator alloc...
Injunction asked 8/1, 2019 at 20:38
2
Solved
With the introduction of if constexpr in c++17, some problems which were solved by using compile-time SFINAE in c++14/c++11 can now be solved using if constexpr, with an easier syntax.
Consider, e...
3
Solved
Before the introduction of concepts and constraints, there are several ways to simulate this compile-time check. Take a "order()" function for example: (how to implement LessThanComparable wi...
Attah asked 25/12, 2018 at 13:9
© 2022 - 2024 — McMap. All rights reserved.