Commit 14121d95 authored by Davis King's avatar Davis King

Added the is_convertible template.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402731
parent 098a1ce9
...@@ -399,6 +399,29 @@ namespace dlib ...@@ -399,6 +399,29 @@ namespace dlib
is_same_type(); is_same_type();
}; };
// ----------------------------------------------------------------------------------------
/*!A is_convertible
This is a template that can be used to determine if one type is convertible
into another type.
For example:
is_convertible<int,float>::value == true // because ints are convertible to floats
is_convertible<int*,float>::value == false // because int pointers are NOT convertible to floats
!*/
template <typename from, typename to>
struct is_convertible
{
struct yes_type { char a; };
struct no_type { yes_type a[2]; };
static const from& from_helper();
static yes_type test(to);
static no_type test(...);
const static bool value = sizeof(test(from_helper())) == sizeof(yes_type);
};
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
/*!A is_signed_type /*!A is_signed_type
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment