sfinae Questions

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...
Vicentevicepresident asked 28/11, 2018 at 6:38

4

Solved

https://www.godbolt.org/z/_4aqsF: template <typename T> struct Container { template <typename TPred> T find_if(TPred pred); // the culprit }; template <typename T> Container&lt...
Lines asked 26/11, 2018 at 16:35

3

Solved

Let's say I have defined a zero_initialize() function: template<class T> T zero_initialize() { T result; std::memset(&result, 0, sizeof(result)); return result; } // usage: auto data...
Cyanamide asked 16/11, 2018 at 13:56

3

Solved

I have a Container class that holds objects whose type may be derived from any combination of some base classes (TypeA, TypeB, etc.). The base class of Container has virtual methods that return a p...
Risky asked 23/10, 2018 at 19:48

3

Solved

I am trying to implement an OutputArchive template class, which has a templated function processImpl(). That looks like this: template<typename ArchiveType> class OutputArchive { ... temp...
Serpentine asked 13/10, 2018 at 21:41

1

Solved

In C++11, it is easy to SFINAE on whether or not an expression is valid. As an example, imagine checking if something is streamable: template <typename T> auto print_if_possible(std::o...
Acidity asked 26/9, 2018 at 9:53

1

#include <iostream> #include <array> #include <vector> template <typename T, typename SFINAE=void> struct trait; template <typename T> struct trait<T, decltype( ...
Sidetrack asked 23/9, 2018 at 2:14

2

Solved

I was playing around with this answer to investigate how it handles functions with default parameters. To my surprise, the results are different for free functions and operator(): template <typ...
Elasticize asked 17/9, 2018 at 14:43

2

Solved

Problem I would like to detect if a class has member variables and fail a static assert if they do. Something like: struct b { int a; } static_assert(!has_member_variables<b>, "Class shoul...
Heredity asked 6/9, 2018 at 15:32

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, ...
Diogenes asked 29/8, 2018 at 18:19

3

Solved

Why can I not use enable_if in the following context? I'd like to detect whether my templated object has the member function notify_exit template <typename Queue> class MyQueue { public: ...
Costly asked 29/8, 2018 at 12:6

2

Solved

I have just discovered the following technique. It looks very close to one of proposed concepts syntax, works perfectly on Clang, GCC and MSVC. template <typename T, typename = typename std::en...
Bryant asked 28/8, 2018 at 1:37

4

I would like to make a type trait for checking if a particular type is hashable using the default instantiations of the standard library's unordered containers, thus if it has a valid specializatio...
Lipscomb asked 5/10, 2012 at 21:3

3

Solved

I'm trying to select a constructor through SFINAE as following: template<typename T> class MyClass { public: template<typename C, typename = std::enable_if_t<std::is_class<C>::v...
Imogeneimojean asked 23/8, 2015 at 13:34

3

Solved

I recently upgraded GCC to 8.2, and most of my SFINAE expressions have stopped working. The following is somewhat simplified, but demonstrates the problem: #include <iostream> #include <...
Olfactory asked 10/8, 2018 at 13:31

1

Solved

Using SFINAE, has_value_int<T> and has_value_auto<T> both try to detect whether class T has a static constexpr function named value. Using int to parametrize true_type, has_value_int&...
Taliped asked 27/7, 2018 at 15:34

1

namespace details { template <std::size_t I = 0, typename Tuple, typename Function, typename... Args> typename std::enable_if<I == std::tuple_size<Tuple>::value, void>::type ForEa...
Dashed asked 6/4, 2017 at 15:41

2

Solved

I have a program that is as follows. There is a base template struct X and a partial specialisation with SFINAE. template <typename T, typename U = void> struct X{ X() { std::cout &l...
Needless asked 23/7, 2018 at 12:38

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&...
Resistencia asked 11/7, 2018 at 19:4

2

Solved

In Chapter 19.8.4 of the book "C++ Templates - The Complete Guide - Second Edition", the authors show how one can determine if a type is a class type in compile-time: #include <iostream> #in...
Valora asked 21/6, 2018 at 18:41

3

In my TClass<T>::foo() function, I'd like to invoke a T instance if and only if T is a function type. #include <iostream> #include <functional> template<class T> struct TC...
Outwit asked 12/6, 2018 at 17:23

1

Solved

This version works fine: template<typename T> struct Foo { template<typename U = T> typename std::enable_if<std::is_same<U,A>::value>::type bar() { std::cout << "1...
Arc asked 6/6, 2018 at 8:47

1

Solved

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::is_referen...
Egidius asked 20/5, 2018 at 23:41

2

Solved

Say I have written a generic function called interpolate. Its signature is like so: template<typename T> T interpolate(T a, T b, float c); Where a and b are the values to interpolate betwe...
Concierge asked 19/5, 2018 at 22:14

3

Solved

Imagine that you have several classes and all of them contain a static variable of the same meaning, but it's names differ in different classes. A toy example: class Point2D { public: static con...
Dicta asked 27/4, 2018 at 13:13

© 2022 - 2024 — McMap. All rights reserved.