mirror of https://github.com/davisking/dlib.git
Added the is_convertible template.
--HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402731
This commit is contained in:
parent
098a1ce990
commit
14121d9588
23
dlib/algs.h
23
dlib/algs.h
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue