Added the is_convertible template.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402731
This commit is contained in:
Davis King 2008-12-19 00:39:24 +00:00
parent 098a1ce990
commit 14121d9588
1 changed files with 23 additions and 0 deletions

View File

@ -399,6 +399,29 @@ namespace dlib
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