Skip to content

Latest commit

 

History

History
73 lines (54 loc) · 1.56 KB

is-convertible-class.md

File metadata and controls

73 lines (54 loc) · 1.56 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: is_convertible Class
is_convertible Class
11/04/2016
type_traits/std::is_convertible
is_convertible class
is_convertible
75614008-1894-42ea-bd57-974399628536

is_convertible Class

Tests if one type is convertible to another.

Syntax

template <class From, class To>
struct is_convertible;

Parameters

From
The type to convert from.

Ty
The type to convert to.

Remarks

An instance of the type predicate holds true if the expression To to = from;, where from is an object of type From, is well-formed.

Example

// std__type_traits__is_convertible.cpp
// compile with: /EHsc
#include <type_traits>
#include <iostream>

struct trivial
    {
    int val;
    };

int main()
    {
    std::cout << "is_convertible<trivial, int> == " << std::boolalpha
        << std::is_convertible<trivial, int>::value << std::endl;
    std::cout << "is_convertible<trivial, trivial> == " << std::boolalpha
        << std::is_convertible<trivial, trivial>::value << std::endl;
    std::cout << "is_convertible<char, int> == " << std::boolalpha
        << std::is_convertible<char, int>::value << std::endl;

    return (0);
    }
is_convertible<trivial, int> == false
is_convertible<trivial, trivial> == true
is_convertible<char, int> == true

Requirements

Header: <type_traits>

Namespace: std

See also

<type_traits>
is_base_of Class