A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../keyword/../types/conditional.html below:

std::conditional - cppreference.com

template< bool B, class T, class F >
struct conditional;

(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.

If the program adds specializations for std::conditional, the behavior is undefined.

[edit] Member types Member type Definition type T if B == true, F if B == false [edit] Helper types

template< bool B, class T, class F >
using conditional_t = typename conditional<B,T,F>::type;

(since C++14) [edit] Possible implementation
template<bool B, class T, class F>
struct conditional { using type = T; };
 
template<class T, class F>
struct conditional<false, T, F> { using type = F; };
[edit] 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:

[edit] See also conditionally removes a function overload or template specialization from overload resolution
(class template) [edit]

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4