sfinae Questions
1
Solved
I have a template class and I would like to have two copy ctors. One for trivial types, and another for non trivial types.
The following code works (with one copy ctor):
template <typename T>...
Speedway asked 21/3, 2021 at 21:26
2
Solved
Code:
#include <iostream>
using std::nullptr_t;
template<typename... T>
using nullptr_vt = nullptr_t;
struct not_addable{};
template<
typename T,
nullptr_vt<decltype(std:...
1
Solved
I am trying to create a templated can_stream struct that inherits from
std::false_type or std::true_type depending on whether operator<< is defined for type T.
#include <iostream>
stru...
Henriettehenriha asked 16/2, 2021 at 20:28
4
Solved
I have seen this question which allows one to check for the existence of a member function, but I'm trying to find out whether a class has a member type.
In the example below, both evaluate to "fa...
Carhop asked 5/8, 2012 at 4:22
1
Solved
I'm just playing around with some SFINAE code and I can't get it to work. I'm using Xcode 12.2 with -std=c++17.
godbolt reveals that Clang does indeed choose the false_type variant no matter ...
Linhliniment asked 7/12, 2020 at 19:32
4
Solved
std::get does not seem to be SFINAE-friendly, as shown by the following test case:
template <class T, class C>
auto foo(C &c) -> decltype(std::get<T>(c)) {
return std::get<T...
Pew asked 17/1, 2017 at 22:53
2
Considering how the comma expression in a decltype() trailing return type can be used to check if a function can be applied:
template <class A>
auto f(A a) -> decltype(check_if_possible(a)...
Scurf asked 18/11, 2020 at 15:36
10
Solved
For creating algorithm template function I need to know whether x or X (and y or Y) in class that is template argument. It may by useful when using my function for MFC CPoint class or GDI+ PointF c...
Nahamas asked 17/6, 2009 at 6:58
17
Solved
I'm asking for a template trick to detect if a class has a specific member function of a given signature.
The problem is similar to the one cited here
http://www.gotw.ca/gotw/071.htm
but not...
5
Solved
I evidently have not enough experience with SFINAE to handle this problem. I actually have the impression that it worked until now, and this kind of problem started to appear like in the last half ...
6
Solved
I am trying to determine which version of a member function gets called based on the class template parameter. I have tried this:
#include <iostream>
#include <type_traits>
temp...
1
Solved
I'm looking for a way to detect if a template class has the methods begin, end and resize.
I tried a modified version of this answer:
#include <iostream>
#include <vector>
// SFINAE te...
1
Solved
I want to use SFINAE to create a templated member function which takes a Consumer functor. Whether something is a consumer depends on a templated static constexpr bool isConsumer member variable. I...
3
Solved
I want to get rid of all the unholy enable_ifs in my templates and replace them with C++20 concepts, however there's barely any info on concepts and the syntax changes with just about any source I ...
Juncaceous asked 14/5, 2020 at 9:19
2
Solved
I'm trying to implement a mechanism to detect whether provided class contains some static method or not. It's quite simple code but I cannot understand why decltype() doesn't work as expected for s...
Fantinlatour asked 8/10, 2017 at 23:3
5
Solved
In template meta programming, one can use SFINAE on the return type to choose a certain template member function, i.e.
template<int N> struct A {
int sum() const noexcept
{ return _s...
Jethro asked 30/1, 2013 at 11:41
1
Solved
I was reading std::enable_if, and noticed the following.
template <typename Integer,
std::enable_if_t<std::is_integral<Integer>::value, int> = 0
>
T(Integer) : m_type(int_t) {}
...
1
Solved
Trying to say goodbye to SFINAE.
Is it possible to use concepts to distinguish between functions, so the compiler can match the correct function based on whether or not a sent parameter meets conc...
Joly asked 26/2, 2020 at 12:50
2
Solved
How is the following an implementation for std::is_function?
template<class T>
struct is_function : std::integral_constant<
bool,
!std::is_const<const T>::value && !std::i...
Yevetteyew asked 8/1, 2020 at 22:6
2
Solved
I am using function SFINAE heavily in a project and am not sure if there are any differences between the following two approaches (other than style):
#include <cstdlib>
#include <ty...
28
Solved
I'd like to be able to introspect a C++ class for its name, contents (i.e. members and their types) etc. I'm talking native C++ here, not managed C++, which has reflection. I realise C++ supplies s...
Onomasiology asked 3/9, 2008 at 10:59
1
Solved
Here's the code:
#include <utility>
#include <type_traits>
template <class T>
class ClassWithDisabledFoo
{
public:
template <class U = T, std::enable_if_t<std::is_integra...
2
The question may be too hard to describe in on sentence in the title, but here is a minimal example:
#include <iostream>
#include <type_traits>
template <class T, class U, class En...
Acetylene asked 20/11, 2019 at 17:29
3
Solved
Consider following code:
#include <iostream>
#include <type_traits>
template <typename T>
struct A {
int val = 0;
template <class = typename std::enable_if<T::val...
Meningitis asked 24/7, 2013 at 18:51
1
Solved
In this video https://youtu.be/Vkck4EU2lOU?t=582 "tag dispatch" and SFINAE are being presented as the alternatives, allowing to achieve selection of the desired template function.
Is it correct? I...
Anticipant asked 30/10, 2019 at 16:48
© 2022 - 2024 — McMap. All rights reserved.