In C++17, a utility metafunction that maps a sequence of any types to the type void.
Questions tagged [void-t]
19 questions
12
votes
1 answer
C++ Templates - The Complete Guide: Understanding footnote comment about decltype and return type
The 2nd edition of C++ Templates - The Complete Guide features the following code at page 435
#include
#include
template
struct HasBeginT : std::false_type {};
template
struct…

Enlico
- 23,259
- 6
- 48
- 102
7
votes
0 answers
SFINAE `std::void_t` class template specialisation
Using SFINAE, I need to detect some properties of a container.
For example:
#include
#include
template
struct Trait {};
template
struct Trait<
Container,
…

BiagioF
- 9,368
- 2
- 26
- 50
7
votes
1 answer
SFINAE-based detection using void_t and protected nest classes
I encountered some divergent behavior between clang and gcc recently regarding void_t property detection and protected/private class information. Consider a type trait defined as follows:
#include
template

apmccartney
- 743
- 8
- 16
6
votes
2 answers
Do C++20 Concepts replace other forms of constraints?
C++20 has landed, bringing with it Concepts. If a project were to start now and target only C++20 and later standards, would it be appropriate to say previous forms of constraints are now superseded by Concepts and the requires clause?
Are there any…

Mark A. Ropper
- 375
- 3
- 12
6
votes
2 answers
Mixing void_t and variadic templates?
Consider the following code:
template >
struct is_invokable
: std::false_type {};
template
struct is_invokable>>
:…

Vincent
- 57,703
- 61
- 205
- 388
4
votes
2 answers
Combining void_t and enable_if?
In C++17, void_t allow to easily do SFINAE with class/struct templates:
template
struct test {
static constexpr auto text = "general case";
};
template
struct test

Vincent
- 57,703
- 61
- 205
- 388
3
votes
1 answer
Compile time error on my void_t wrapper intead of fallback
Lately i tried to write wrapper arount void_t idiom simple as following:
namespace detail {
template
struct applicable : std::false_type {};
template
struct applicable,…

David
- 125
- 8
3
votes
1 answer
Why does this custom type trait not compile
I'm not sure what I've done wrong below. I'm trying to write a trait can_visit and using the standard pattern of std::void_t and sfinae but it just won't compile and keeps telling me there is an error in the decltype statement containing the…

bradgonesurfing
- 30,949
- 17
- 114
- 217
3
votes
1 answer
SFINAE without void_t (maybe a template specialization question)
Sorry for the title, I am not sure about the category of my question.
I am trying to do an is_incrementable with SFINAE. This works fine, however when I try to understand it more deeply, and when I remove the void_t then the code snippet does not…

thamas
- 183
- 2
- 9
3
votes
1 answer
C++ void_t SFINAE false_type true_type can't get specialization
It all seemed simple.
Shouldn't has_member_type::value be true for T=vector in my code below? Sorry if it had already be answered. I looked for a while, but couldn't find an answer.
#include
#include
//…
user9987379
2
votes
3 answers
Reliable way of ordering mulitple std::void_t partial specializations for type traits
I want to classify the "level of feature support" for a type.
The type can contain aliases red and blue. It can contain just one, both , or neither, and I want to classify each of these cases with an enum class:
enum class holder_type {
none,
…

Jan Schultke
- 17,446
- 6
- 47
- 96
2
votes
2 answers
What is the purpose of "int[]" here: "std::void_t(-1) < static_cast(0)]>;"
This is from an example from a tutorial on std::enable_if.
Here is more context:
// handle signed types
template
auto incr1(Int& target, Int amount)
-> std::void_t(-1) < static_cast(0)]>;
From
Shouldn't…

Octo
- 77
- 4
2
votes
0 answers
Why std::void_t is required to detect ill-formed types in SFINAE context?
I have is_callable trait as below:
template
struct is_callable: std::false_type {};
template
struct is_callable>: std::true_type {}; // (A)
There I have to wrap…

oliora
- 839
- 5
- 12
2
votes
1 answer
Why does this use of the detection idiom result in different compilation errors for Clang and GCC and none for MSVC
While playing around with the detection idiom and void_t I found that expressions where the subtraction operator and void* are involved lead to different errors in the tested compilers.
GCC 10.2 and below, no matter if C++11,14,17 or 20 is used,…

jesses
- 559
- 3
- 15
2
votes
1 answer
Beside concepts are there any other void_t replacements in C++20?
Assuming I do not want to write a concept (or my compiler does not support them) and there is no matching type trait is there C++20 non void_t way to check if I can construct A with arguments B and C?
Note: this is a toy example, real question is is…

NoSenseEtAl
- 28,205
- 28
- 128
- 277