- added is_const template

- changed the member_function_pointer_kernel_1 slightly so that it
  compiles in visual studio.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402615
This commit is contained in:
Davis King 2008-10-31 03:53:53 +00:00
parent 72d9adbf50
commit e3fd5442b3
2 changed files with 40 additions and 5 deletions

View File

@ -346,6 +346,25 @@ namespace dlib
is_pointer_type();
};
// ----------------------------------------------------------------------------------------
/*!A is_const
This is a template where is_const<T>::value == true when T is a const
type ane false otherwise.
!*/
template <typename T>
struct is_const
{
static const bool value = false;
};
template <typename T>
struct is_const<const T>
{
static const bool value = true;
};
// ----------------------------------------------------------------------------------------
/*!A is_same_type

View File

@ -5,6 +5,7 @@
#include "../algs.h"
#include "member_function_pointer_kernel_abstract.h"
#include "../enable_if.h"
#include <new>
namespace dlib
@ -207,7 +208,10 @@ namespace dlib
{ COMPILE_TIME_ASSERT(sizeof(mp_memory.data) >= sizeof(mp_impl_T<mp_impl<dummy> >));
COMPILE_TIME_ASSERT(sizeof(mp_memory.data) >= sizeof(mp_impl_T<mp_impl_const<dummy> >)); }
template <typename T> void set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
// the reason for putting disable_if on this function is that it avoids an overload
// resolution bug in visual studio.
template <typename T> typename disable_if<is_const<T>,void>::type
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
{ mp_impl_T<mp_impl<T> >(&object,cb).clone(mp_memory.data); }
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
@ -263,7 +267,10 @@ namespace dlib
{ COMPILE_TIME_ASSERT(sizeof(mp_memory.data) >= sizeof(mp_impl_T<mp_impl<dummy> >));
COMPILE_TIME_ASSERT(sizeof(mp_memory.data) >= sizeof(mp_impl_T<mp_impl_const<dummy> >)); }
template <typename T> void set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
// the reason for putting disable_if on this function is that it avoids an overload
// resolution bug in visual studio.
template <typename T> typename disable_if<is_const<T>,void>::type
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
{ mp_impl_T<mp_impl<T> >(&object,cb).clone(mp_memory.data); }
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
@ -320,7 +327,10 @@ namespace dlib
{ COMPILE_TIME_ASSERT(sizeof(mp_memory.data) >= sizeof(mp_impl_T<mp_impl<dummy> >));
COMPILE_TIME_ASSERT(sizeof(mp_memory.data) >= sizeof(mp_impl_T<mp_impl_const<dummy> >)); }
template <typename T> void set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
// the reason for putting disable_if on this function is that it avoids an overload
// resolution bug in visual studio.
template <typename T> typename disable_if<is_const<T>,void>::type
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
{ mp_impl_T<mp_impl<T> >(&object,cb).clone(mp_memory.data); }
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
@ -378,7 +388,10 @@ namespace dlib
{ COMPILE_TIME_ASSERT(sizeof(mp_memory.data) >= sizeof(mp_impl_T<mp_impl<dummy> >));
COMPILE_TIME_ASSERT(sizeof(mp_memory.data) >= sizeof(mp_impl_T<mp_impl_const<dummy> >)); }
template <typename T> void set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
// the reason for putting disable_if on this function is that it avoids an overload
// resolution bug in visual studio.
template <typename T> typename disable_if<is_const<T>,void>::type
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
{ mp_impl_T<mp_impl<T> >(&object,cb).clone(mp_memory.data); }
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
@ -438,7 +451,10 @@ namespace dlib
{ COMPILE_TIME_ASSERT(sizeof(mp_memory.data) >= sizeof(mp_impl_T<mp_impl<dummy> >));
COMPILE_TIME_ASSERT(sizeof(mp_memory.data) >= sizeof(mp_impl_T<mp_impl_const<dummy> >)); }
template <typename T> void set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
// the reason for putting disable_if on this function is that it avoids an overload
// resolution bug in visual studio.
template <typename T> typename disable_if<is_const<T>,void>::type
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
{ mp_impl_T<mp_impl<T> >(&object,cb).clone(mp_memory.data); }
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)