enable-if Questions
1
Solved
Basic Problem Statement
I'm learning about SFINAE. I tried an extremely simple enable_if:
// 1: A foo() that accepts arguments that are derived from Base
template <typename T, typename Enable ...
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 {
...
3
So yet another question in this saga. Guillaume Racicot has been good enough to provide me with yet another workaround so this is the code I'll be basing this question off of:
struct vec
{
double...
Demiurge asked 19/6, 2019 at 12:38
1
Solved
I want to declare something like this:
template <typename T>
constexpr enable_if_t<is_integral_v<T>, int[]> foo = { 1, 2 };
template <typename T>
constexpr enable_if_t<...
Kara asked 14/6, 2019 at 12:44
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...
2
Solved
I am trying to specialize a template this way:
class PropertyBase
{
public:
SfPropertyBase(string name)
{
Name = name;
}
virtual ~SfPropertyBase() {}
string Name;
virtual bool FromString...
Rosaleerosaleen asked 21/5, 2019 at 6:13
2
Solved
I'm trying to create a template function taking a typename. I want to specialize this templates for some basic types like int, long, string and double. For all others types, i need to have a specia...
Papen asked 12/4, 2019 at 8:45
1
Solved
I have problems with GCC compiling enable_ifs applied to the return value of the templated class method. With Clang, I am able to use an expression in enable_if on the enum template argument, while...
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
1
Solved
For example if I have
#include <type_traits>
struct OwnershipReceiver
{
template <typename T,
class = typename std::enable_if
<
!std::is_lvalue_reference<T>::value
>::ty...
2
I have many EnableIf traits that basically check whether the input type satisfies an interface. I was trying to create a generic Resolve trait that can be used to transform those into a boolean tra...
3
Solved
Suppose we have some SFINAE member function:
class foo{
template <class S, class = std::enable_if_t<std::is_integral<S>::value, S>
void bar(S&& s);
template <class S, ...
3
Solved
I want to write a templatized function which takes either an array<int, 3> or an int[3]. I'm trying to capture that in an enable_if:
template<typename T>
enable_if_t<is_array_v<T...
Whisenhunt asked 29/8, 2018 at 14:27
3
Solved
I'm building some input checker that needs to have specific functions for integer and/or double (for example 'isPrime' should only be available for integers).
If I'm using enable_if as a par...
1
Solved
I need to write a templated function, that behaves differently depending on the class of its parameter:
template<class ContainerType>
bool myFunc(ContainerType in){
//do some stuff
}
templa...
Geriatrician asked 25/7, 2018 at 8:28
2
Solved
I have been liking SFINAE syntax like this for functions, seems to generally work well!
template <class Integer, class = typename std::enable_if<std::is_integral<Integer>::value&...
2
Solved
#include<string>
#include<type_traits>
template<typename... Args>
class C {
public:
void foo(Args&&... args) {
}
template<typename = std::enable_if_t<(0 < ...
Lemon asked 6/6, 2018 at 6:36
1
Solved
I am learning how to use std::enable_if and I have had some degree of success so far at conditionally enabling and disabling methods in my classes. I template the methods against a boolean, a...
Rickart asked 28/5, 2018 at 7:28
1
I'm currently wrestling with Visual Studio 2017 (compiling using /std:c++latest if that's any help).
The code in question simply selects a struct specialization based on the result of some templa...
Genitalia asked 10/9, 2017 at 18:25
1
Solved
This question combines several pieces of code and is a bit complicated, but I tried slimming it down as much as possible.
I am trying to use std::enable_if to conditionally invoke the correct cons...
Carbamate asked 14/3, 2018 at 20:20
2
Solved
In C++17, void_t allow to easily do SFINAE with class/struct templates:
template <class T, class = void>
struct test {
static constexpr auto text = "general case";
};
template <...
Pus asked 1/3, 2018 at 8:24
0
I get what appears to be a Visual Studio bug when I compile time test if a type with a default template parameter has some property. In the minimal example below I use std::is_integer.
When compil...
Freida asked 27/2, 2018 at 7:54
3
Solved
These two non-variadic function templates do compile:
template <typename T, typename U>
typename std::enable_if<std::is_same<U, int>::value, void>::
type testFunction(T a, U b) {...
Equiangular asked 13/2, 2018 at 10:9
3
Solved
I'm a bit confused about partial template specialization... I have some code that depends on an arithmetic data type T, and on a small integer DIM. I want to be able to specify different class meth...
Crayton asked 19/12, 2017 at 2:28
2
Solved
I am trying std::enable_if for the first time and struggling. Any guidance would be appreciated.
As a toy example, here is a simple static vector class, for which I want to define a copy constructo...
© 2022 - 2024 — McMap. All rights reserved.