On this page
std::conditional
Defined in header <type_traits> |
||
---|---|---|
|
(since C++11) |
Provides member typedef type
, which is defined as T
if B
is true
at compile time, or as F
if B
is false
.
The behavior of a program that adds specializations for std::conditional
is undefined.
Member types
Member type | Definition |
---|---|
type |
T if B == true , F if B == false |
Helper types
|
(since C++14) |
Possible implementation
|
Example
#include <iostream>
#include <type_traits>
#include <typeinfo>
int main()
{
using Type1 = std::conditional<true, int, double>::type;
using Type2 = std::conditional<false, int, double>::type;
using Type3 = std::conditional<sizeof(int) >= sizeof(double), int, double>::type;
std::cout << typeid(Type1).name() << '\n';
std::cout << typeid(Type2).name() << '\n';
std::cout << typeid(Type3).name() << '\n';
}
Possible output:
int
double
double
See also
(C++11)
|
conditionally removes a function overload or template specialization from overload resolution (class template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/types/conditional