📄 mstl_type_traits.hpp
字号:
/*
The young Library
Copyright (c) 2005 by 杨桓
Permission to use, copy, modify, distribute and sell this software for any
purpose is hereby granted without fee, provided that the above copyright
notice appear in all copies and that both that copyright notice and this
permission notice appear in supporting documentation.
The author make no representations about the suitability of this software
for any purpose. It is provided "as is" without express or implied warranty.
*/
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#ifndef __MACRO_CPLUSPLUS_MINI_STL_TYPE_TRAITS_HEADER_FILE__
#define __MACRO_CPLUSPLUS_MINI_STL_TYPE_TRAITS_HEADER_FILE__
//-----------------------------------------------------------------------------
#include "mstl_define.hpp"
//-----------------------------------------------------------------------------
__MACRO_CPLUSPLUS_MINI_STL_BEGIN_NAMESPACE__
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
struct true_type {};
struct false_type {};
template< typename T >
struct type_traits
{
typedef false_type has_trivial_default_constructor;
typedef false_type has_trivial_copy_constructor;
typedef false_type has_trivial_assignment_operator;
typedef false_type has_trivial_destructor;
typedef false_type is_POD_type;
};
template< typename T >
struct type_traits<T*>
{
typedef true_type has_trivial_default_constructor;
typedef true_type has_trivial_copy_constructor;
typedef true_type has_trivial_assignment_operator;
typedef true_type has_trivial_destructor;
typedef true_type is_POD_type;
};
template<>
struct type_traits<void*>
{
typedef true_type has_trivial_default_constructor;
typedef true_type has_trivial_copy_constructor;
typedef true_type has_trivial_assignment_operator;
typedef true_type has_trivial_destructor;
typedef true_type is_POD_type;
};
template<>
struct type_traits<void>
{
typedef true_type has_trivial_default_constructor;
typedef true_type has_trivial_copy_constructor;
typedef true_type has_trivial_assignment_operator;
typedef true_type has_trivial_destructor;
typedef true_type is_POD_type;
};
template<>
struct type_traits<bool>
{
typedef true_type has_trivial_default_constructor;
typedef true_type has_trivial_copy_constructor;
typedef true_type has_trivial_assignment_operator;
typedef true_type has_trivial_destructor;
typedef true_type is_POD_type;
};
template<>
struct type_traits<char>
{
typedef true_type has_trivial_default_constructor;
typedef true_type has_trivial_copy_constructor;
typedef true_type has_trivial_assignment_operator;
typedef true_type has_trivial_destructor;
typedef true_type is_POD_type;
};
template<>
struct type_traits<signed char>
{
typedef true_type has_trivial_default_constructor;
typedef true_type has_trivial_copy_constructor;
typedef true_type has_trivial_assignment_operator;
typedef true_type has_trivial_destructor;
typedef true_type is_POD_type;
};
template<>
struct type_traits<unsigned char>
{
typedef true_type has_trivial_default_constructor;
typedef true_type has_trivial_copy_constructor;
typedef true_type has_trivial_assignment_operator;
typedef true_type has_trivial_destructor;
typedef true_type is_POD_type;
};
template<>
struct type_traits<short>
{
typedef true_type has_trivial_default_constructor;
typedef true_type has_trivial_copy_constructor;
typedef true_type has_trivial_assignment_operator;
typedef true_type has_trivial_destructor;
typedef true_type is_POD_type;
};
template<>
struct type_traits<unsigned short>
{
typedef true_type has_trivial_default_constructor;
typedef true_type has_trivial_copy_constructor;
typedef true_type has_trivial_assignment_operator;
typedef true_type has_trivial_destructor;
typedef true_type is_POD_type;
};
template<>
struct type_traits<int>
{
typedef true_type has_trivial_default_constructor;
typedef true_type has_trivial_copy_constructor;
typedef true_type has_trivial_assignment_operator;
typedef true_type has_trivial_destructor;
typedef true_type is_POD_type;
};
template<>
struct type_traits<unsigned int>
{
typedef true_type has_trivial_default_constructor;
typedef true_type has_trivial_copy_constructor;
typedef true_type has_trivial_assignment_operator;
typedef true_type has_trivial_destructor;
typedef true_type is_POD_type;
};
template<>
struct type_traits<long>
{
typedef true_type has_trivial_default_constructor;
typedef true_type has_trivial_copy_constructor;
typedef true_type has_trivial_assignment_operator;
typedef true_type has_trivial_destructor;
typedef true_type is_POD_type;
};
template<>
struct type_traits<unsigned long>
{
typedef true_type has_trivial_default_constructor;
typedef true_type has_trivial_copy_constructor;
typedef true_type has_trivial_assignment_operator;
typedef true_type has_trivial_destructor;
typedef true_type is_POD_type;
};
template<>
struct type_traits<float>
{
typedef true_type has_trivial_default_constructor;
typedef true_type has_trivial_copy_constructor;
typedef true_type has_trivial_assignment_operator;
typedef true_type has_trivial_destructor;
typedef true_type is_POD_type;
};
template<>
struct type_traits<double>
{
typedef true_type has_trivial_default_constructor;
typedef true_type has_trivial_copy_constructor;
typedef true_type has_trivial_assignment_operator;
typedef true_type has_trivial_destructor;
typedef true_type is_POD_type;
};
template<>
struct type_traits<long double>
{
typedef true_type has_trivial_default_constructor;
typedef true_type has_trivial_copy_constructor;
typedef true_type has_trivial_assignment_operator;
typedef true_type has_trivial_destructor;
typedef true_type is_POD_type;
};
/*
template<>
struct type_traits<long long>
{
typedef true_type has_trivial_default_constructor;
typedef true_type has_trivial_copy_constructor;
typedef true_type has_trivial_assignment_operator;
typedef true_type has_trivial_destructor;
typedef true_type is_POD_type;
};
template<>
struct type_traits<unsigned long long>
{
typedef true_type has_trivial_default_constructor;
typedef true_type has_trivial_copy_constructor;
typedef true_type has_trivial_assignment_operator;
typedef true_type has_trivial_destructor;
typedef true_type is_POD_type;
};
*/
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
template< typename T >
struct primal_type
{
typedef T primal_t;
typedef const T contrary_const;
typedef const T* contrary_const_ptr;
typedef const T& contrary_const_ref;
};
template< typename T >
struct primal_type<const T>
{
typedef T primal_t;
typedef T contrary_const;
typedef T* contrary_const_ptr;
typedef T& contrary_const_ref;
};
template< typename T >
struct primal_type<T*>
{
typedef T primal_t;
typedef const T contrary_const;
typedef const T* contrary_const_ptr;
typedef const T& contrary_const_ref;
};
template< typename T >
struct primal_type<const T*>
{
typedef T primal_t;
typedef T contrary_const;
typedef T* contrary_const_ptr;
typedef T& contrary_const_ref;
};
template< typename T >
struct primal_type<T&>
{
typedef T primal_t;
typedef const T contrary_const;
typedef const T* contrary_const_ptr;
typedef const T& contrary_const_ref;
};
template< typename T >
struct primal_type<const T&>
{
typedef T primal_t;
typedef T contrary_const;
typedef T* contrary_const_ptr;
typedef T& contrary_const_ref;
};
//-----------------------------------------------------------------------------
struct same_type {};
struct different_type {};
template< typename T1, typename T2 >
struct types_matching
{
typedef different_type matching;
};
template< typename T >
struct types_matching<T, T>
{
typedef same_type matching;
};
//-----------------------------------------------------------------------------
template< typename T1, typename T2 >
struct double_types_traits
{
typedef typename primal_type<T1>::primal_t primal_t1;
typedef typename primal_type<T2>::primal_t primal_t2;
typedef typename types_matching<primal_t1, primal_t2>::result
matching_result;
typedef typename type_traits<primal_t1>::has_trivial_default_constructor
has_trivial_default_constructor_t1;
typedef typename type_traits<primal_t1>::has_trivial_copy_constructor
has_trivial_copy_constructor_t1;
typedef typename type_traits<primal_t1>::has_trivial_assignment_operator
has_trivial_assignment_operator_t1;
typedef typename type_traits<primal_t1>::has_trivial_destructor
has_trivial_destructor_t1;
typedef typename type_traits<primal_t1>::is_POD_type
is_POD_type_t1;
typedef typename type_traits<primal_t2>::has_trivial_default_constructor
has_trivial_default_constructor_t2;
typedef typename type_traits<primal_t2>::has_trivial_copy_constructor
has_trivial_copy_constructor_t2;
typedef typename type_traits<primal_t2>::has_trivial_assignment_operator
has_trivial_assignment_operator_t2;
typedef typename type_traits<primal_t2>::has_trivial_destructor
has_trivial_destructor_t2;
typedef typename type_traits<primal_t2>::is_POD_type
is_POD_type_t2;
};
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
__MACRO_CPLUSPLUS_MINI_STL_END_NAMESPACE__
#endif
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -