sfinae Questions
2
1
I noted that much of boost and libc++/libstdc++ explicitly provide a default value of zero for SFINAE in code like
// libc++ http://llvm.org/svn/llvm-project/libcxx/trunk/include/memory
namespace ...
3
Solved
Whats wrong with this:
#include <type_traits>
struct A;
template<typename T>
struct B
{
template<typename=std::enable_if<std::is_copy_constructible<T>::value>>
vo...
Kabob asked 10/10, 2019 at 10:5
5
Solved
I have the following case that works using std::enable_if :
template<typename T,
typename std::enable_if<std::is_same<int, T>::value>::type* = nullptr>
void f() { }
template&l...
7
Solved
In short:
How to write a test, that checks that my class is not copyable or copy-assignable, but is only moveable and move-assignable?
In general:
How to write a test, that makes sure that a spe...
Allpurpose asked 8/5, 2014 at 16:46
2
Solved
I wrote the following template function, which checks whether an arbitary container contains a specific element:
template<template<class, class...> class container_t, class item_t, class....
Translative asked 8/4, 2015 at 17:6
2
I am learning some modern C++20 features. One of them is concept. I have read https://en.cppreference.com/w/cpp/language/constraints and https://www.modernescpp.com/index.php/defintion-of-concepts ...
4
Solved
Given:
struct A
{
virtual bool what() = 0;
};
template<typename T, typename Q>
struct B : public A
{
virtual bool what();
};
I want to partially specialize what like:
template<typen...
Greenleaf asked 23/4, 2012 at 16:31
5
Solved
Scott Meyers posted content and status of his next book EC++11.
He wrote that one item in the book could be "Avoid std::enable_if in function signatures".
std::enable_if can be used as a function ...
4
Solved
I found several questions & answers on SO dealing with detecting at compile time (via SFINAE) whether a given class has a member of certain name, type, or signature. However, I couldn't find on...
Polyclitus asked 17/4, 2014 at 12:53
2
Solved
About a year or two ago I read about SFINAE rules in C++. They state, in particular,
The following type errors are SFINAE errors:
...
attempting to create an array of void, array of reference, arr...
Willywillynilly asked 20/9, 2023 at 11:15
3
Solved
I have a problem in my application where I'd like to assert that a function application would be rejected by the compiler. Is there a way to check this with SFINAE?
For example, assume that I'd li...
Cartwright asked 5/5, 2012 at 0:39
3
Solved
I just found out how to check if operator<< is provided for a type.
template<class T> T& lvalue_of_type();
template<class T> T rvalue_of_type();
template<class T>
stru...
Graybill asked 24/1, 2010 at 16:11
1
An SFINAE technique is to to use a default class to enable/disable a function. However this doesn't work with overloading functions, resulting in "template parameter redefines default argument...
Septivalent asked 24/1, 2021 at 12:27
1
The title should clarify what my confusion is about. I'd like to use this question to get a comprehensive answer which helps me understand how the comma operator works with decltype within SFINAE c...
Sphagnum asked 28/9, 2021 at 18:11
5
Solved
I’m trying to use static_assert to force something to fail. If you try to instantiate a specific templated function in a specific way I want to generate a complier error. I could make it work, but ...
Nara asked 19/5, 2017 at 0:14
3
Solved
I would like to write a C++ function that will check that its template parameter class is incomplete, so only class declaration is available but not full definition with all class members.
My...
Jehad asked 29/7, 2021 at 9:50
14
Solved
I am trying to create an example, which would check the existence of the operator== (member or, non-member function). To check whether a class has a member operator== is easy, but how to check whet...
3
Solved
Paragraph 14.8.2/8 of the C++11 Standard specifies the conditions under which a substitution failure shall or shall not result in a "hard" compilation error (thereby causing compilation to fail) or...
Stoppage asked 7/3, 2013 at 0:6
8
Solved
Here's what I'm trying to do:
template <typename T> struct Model
{
vector<T> vertices ;
#if T has a .normal member
void transform( Matrix m )
{
each vertex in vertices
{
vertex...
2
Solved
I saw this example of using SFINAE to check if a type is streamable here. However, I noticed that it is not portable, i.e. returns different results for templated types with different compilers. I'...
Bialy asked 6/9, 2022 at 5:41
2
The code in this question is based on this answer. I am a little confused about how this produces the output it does, and whether it is all well defined
#include <type_traits>
#include <io...
Shiri asked 10/8, 2022 at 15:30
2
Solved
I'm writing some type traits to see if a free function exists with a specific set of parameters. The functions have a signature that looks something like this:
template <class T> void func( ...
Cockrell asked 17/3, 2014 at 20:5
1
Solved
Simple code as below or as on godbolt doesn't compile with clang but compiles fine with gcc and Visual Studio.
The trailing return type decltype(foo(t)) of baz(T t) is not evaluated when SFINAE fai...
Neckcloth asked 31/5, 2022 at 16:59
3
Solved
I needed a type trait that decays enums to their underlying type, and works the same as decay_t for all other types. I've written the following code, and apparently this is not how SFINAE works. Bu...
Hotchpotch asked 11/5, 2022 at 7:45
1 Next >
© 2022 - 2024 — McMap. All rights reserved.