Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

is_convertible Class

Tests if one type is convertible to another.

template<class From, class To>
    struct is_convertible;

The type to convert from.


The type to convert to.

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.


// std_tr1__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

Header: <type_traits>

Namespace: std

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.