⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ycpp_traits.hpp

📁 一个类STL的多平台可移植的算法容器库,主要用于嵌入式系统编程时的内存管理等方面
💻 HPP
字号:
/*
 * The young Library
 * Copyright (c) 2005 by Yang Huan(杨桓)

 * 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_YOUNG_LIBRARY_TRAITS_HEADER_FILE__
#define __MACRO_CPLUSPLUS_YOUNG_LIBRARY_TRAITS_HEADER_FILE__
//------------------------------------------------------------------------------
#include "ycpp_configuration.hpp"

#ifdef __MACRO_CPLUSPLUS_YOUNG_LIBRARY_COMPILER_SUPPORT_STANDARD_TYPE_TRAITS__
    #include <type_traits>
#endif
//------------------------------------------------------------------------------
namespace youngcpp {
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------

#ifdef __MACRO_CPLUSPLUS_YOUNG_LIBRARY_COMPILER_SUPPORT_STANDARD_TYPE_TRAITS__
    typedef  std::tr1::true_type   true_type;
    typedef  std::tr1::false_type  false_type;

    template< typename T >
    struct property_traits
    {
        typedef  typename std::tr1::is_pod<T>::type  is_POD;
        typedef  typename std::tr1::has_trivial_constructor<T>::type
                 has_trivial_constructor;
        typedef  typename std::tr1::has_trivial_copy<T>::type
                 has_trivial_copy;
        typedef  typename std::tr1::has_trivial_assign<T>::type
                 has_trivial_assign;
        typedef  typename std::tr1::has_trivial_destructor<T>::type
                 has_trivial_destructor;

        static const bool pod = std::tr1::is_pod<T>::value;
        static const bool trivial_constructor
                          = std::tr1::has_trivial_constructor<T>::value;
        static const bool trivial_copy
                          = std::tr1::has_trivial_copy<T>::value;
        static const bool trivial_assign
                          = std::tr1::has_trivial_assign<T>::value;
        static const bool trivial_destructor
                          = std::tr1::has_trivial_destructor<T>::value;
    };
#else
    struct true_type  {};
    struct false_type {};

    template< typename T >
    struct property_traits
    {
        typedef  false_type  is_POD;
        typedef  false_type  has_trivial_constructor;
        typedef  false_type  has_trivial_copy;
        typedef  false_type  has_trivial_assign;
        typedef  false_type  has_trivial_destructor;

        static const bool pod = false;
        static const bool trivial_constructor = false;
        static const bool trivial_copy = false;
        static const bool trivial_assign = false;
        static const bool trivial_destructor = false;
    };

    template< typename T >
    struct property_traits<T*>
    {
        typedef  true_type  is_POD;
        typedef  true_type  has_trivial_constructor;
        typedef  true_type  has_trivial_copy;
        typedef  true_type  has_trivial_assign;
        typedef  true_type  has_trivial_destructor;

        static const bool pod = true;
        static const bool trivial_constructor = true;
        static const bool trivial_copy = true;
        static const bool trivial_assign = true;
        static const bool trivial_destructor = true;
    };

    template<>
    struct property_traits<bool>
    {
        typedef  true_type  is_POD;
        typedef  true_type  has_trivial_constructor;
        typedef  true_type  has_trivial_copy;
        typedef  true_type  has_trivial_assign;
        typedef  true_type  has_trivial_destructor;

        static const bool pod = true;
        static const bool trivial_constructor = true;
        static const bool trivial_copy = true;
        static const bool trivial_assign = true;
        static const bool trivial_destructor = true;
    };

    template<>
    struct property_traits<char>
    {
        typedef  true_type  is_POD;
        typedef  true_type  has_trivial_constructor;
        typedef  true_type  has_trivial_copy;
        typedef  true_type  has_trivial_assign;
        typedef  true_type  has_trivial_destructor;

        static const bool pod = true;
        static const bool trivial_constructor = true;
        static const bool trivial_copy = true;
        static const bool trivial_assign = true;
        static const bool trivial_destructor = true;
    };

    template<>
    struct property_traits<signed char>
    {
        typedef  true_type  is_POD;
        typedef  true_type  has_trivial_constructor;
        typedef  true_type  has_trivial_copy;
        typedef  true_type  has_trivial_assign;
        typedef  true_type  has_trivial_destructor;

        static const bool pod = true;
        static const bool trivial_constructor = true;
        static const bool trivial_copy = true;
        static const bool trivial_assign = true;
        static const bool trivial_destructor = true;
    };

    template<>
    struct property_traits<unsigned char>
    {
        typedef  true_type  is_POD;
        typedef  true_type  has_trivial_constructor;
        typedef  true_type  has_trivial_copy;
        typedef  true_type  has_trivial_assign;
        typedef  true_type  has_trivial_destructor;

        static const bool pod = true;
        static const bool trivial_constructor = true;
        static const bool trivial_copy = true;
        static const bool trivial_assign = true;
        static const bool trivial_destructor = true;
    };

    template<>
    struct property_traits<short>
    {
        typedef  true_type  is_POD;
        typedef  true_type  has_trivial_constructor;
        typedef  true_type  has_trivial_copy;
        typedef  true_type  has_trivial_assign;
        typedef  true_type  has_trivial_destructor;

        static const bool pod = true;
        static const bool trivial_constructor = true;
        static const bool trivial_copy = true;
        static const bool trivial_assign = true;
        static const bool trivial_destructor = true;
    };

    template<>
    struct property_traits<unsigned short>
    {
        typedef  true_type  is_POD;
        typedef  true_type  has_trivial_constructor;
        typedef  true_type  has_trivial_copy;
        typedef  true_type  has_trivial_assign;
        typedef  true_type  has_trivial_destructor;

        static const bool pod = true;
        static const bool trivial_constructor = true;
        static const bool trivial_copy = true;
        static const bool trivial_assign = true;
        static const bool trivial_destructor = true;
    };

    template<>
    struct property_traits<int>
    {
        typedef  true_type  is_POD;
        typedef  true_type  has_trivial_constructor;
        typedef  true_type  has_trivial_copy;
        typedef  true_type  has_trivial_assign;
        typedef  true_type  has_trivial_destructor;

        static const bool pod = true;
        static const bool trivial_constructor = true;
        static const bool trivial_copy = true;
        static const bool trivial_assign = true;
        static const bool trivial_destructor = true;
    };

    template<>
    struct property_traits<unsigned int>
    {
        typedef  true_type  is_POD;
        typedef  true_type  has_trivial_constructor;
        typedef  true_type  has_trivial_copy;
        typedef  true_type  has_trivial_assign;
        typedef  true_type  has_trivial_destructor;

        static const bool pod = true;
        static const bool trivial_constructor = true;
        static const bool trivial_copy = true;
        static const bool trivial_assign = true;
        static const bool trivial_destructor = true;
    };

    template<>
    struct property_traits<long>
    {
        typedef  true_type  is_POD;
        typedef  true_type  has_trivial_constructor;
        typedef  true_type  has_trivial_copy;
        typedef  true_type  has_trivial_assign;
        typedef  true_type  has_trivial_destructor;

        static const bool pod = true;
        static const bool trivial_constructor = true;
        static const bool trivial_copy = true;
        static const bool trivial_assign = true;
        static const bool trivial_destructor = true;
    };

    template<>
    struct property_traits<unsigned long>
    {
        typedef  true_type  is_POD;
        typedef  true_type  has_trivial_constructor;
        typedef  true_type  has_trivial_copy;
        typedef  true_type  has_trivial_assign;
        typedef  true_type  has_trivial_destructor;

        static const bool pod = true;
        static const bool trivial_constructor = true;
        static const bool trivial_copy = true;
        static const bool trivial_assign = true;
        static const bool trivial_destructor = true;
    };

    template<>
    struct property_traits<float>
    {
        typedef  true_type  is_POD;
        typedef  true_type  has_trivial_constructor;
        typedef  true_type  has_trivial_copy;
        typedef  true_type  has_trivial_assign;
        typedef  true_type  has_trivial_destructor;

        static const bool pod = true;
        static const bool trivial_constructor = true;
        static const bool trivial_copy = true;
        static const bool trivial_assign = true;
        static const bool trivial_destructor = true;
    };

    template<>
    struct property_traits<double>
    {
        typedef  true_type  is_POD;
        typedef  true_type  has_trivial_constructor;
        typedef  true_type  has_trivial_copy;
        typedef  true_type  has_trivial_assign;
        typedef  true_type  has_trivial_destructor;

        static const bool pod = true;
        static const bool trivial_constructor = true;
        static const bool trivial_copy = true;
        static const bool trivial_assign = true;
        static const bool trivial_destructor = true;
    };

    template<>
    struct property_traits<long double>
    {
        typedef  true_type  is_POD;
        typedef  true_type  has_trivial_constructor;
        typedef  true_type  has_trivial_copy;
        typedef  true_type  has_trivial_assign;
        typedef  true_type  has_trivial_destructor;

        static const bool pod = true;
        static const bool trivial_constructor = true;
        static const bool trivial_copy = true;
        static const bool trivial_assign = true;
        static const bool trivial_destructor = true;
    };

    #ifdef __MACRO_CPLUSPLUS_YOUNG_LIBRARY_COMPILER_SUPPORT_LONG_LONG_TYPE__
        template<>
        struct property_traits<long long>
        {
            typedef  true_type  is_POD;
            typedef  true_type  has_trivial_constructor;
            typedef  true_type  has_trivial_copy;
            typedef  true_type  has_trivial_assign;
            typedef  true_type  has_trivial_destructor;

            static const bool pod = true;
            static const bool trivial_constructor = true;
            static const bool trivial_copy = true;
            static const bool trivial_assign = true;
            static const bool trivial_destructor = true;
        };

        template<>
        struct property_traits<unsigned long long>
        {
            typedef  true_type  is_POD;
            typedef  true_type  has_trivial_constructor;
            typedef  true_type  has_trivial_copy;
            typedef  true_type  has_trivial_assign;
            typedef  true_type  has_trivial_destructor;

            static const bool pod = true;
            static const bool trivial_constructor = true;
            static const bool trivial_copy = true;
            static const bool trivial_assign = true;
            static const bool trivial_destructor = true;
        };
    #endif  //SUPPORT_LONG_LONG_TYPE
#endif      //SUPPORT_STANDARD_TYPE_TRAITS

//------------------------------------------------------------------------------

template< typename T >
struct primal_traits
{
    typedef  T         primal_t;
    typedef  const T   contrary_const_t;
    typedef  const T*  contrary_const_ptr;
    typedef  const T&  contrary_const_ref;
};

template< typename T >
struct primal_traits<const T>
{
    typedef  T   primal_t;
    typedef  T   contrary_const_t;
    typedef  T*  contrary_const_ptr;
    typedef  T&  contrary_const_ref;
};

template< typename T >
struct primal_traits<T*>
{
    typedef  T         primal_t;
    typedef  const T   contrary_const_t;
    typedef  const T*  contrary_const_ptr;
    typedef  const T&  contrary_const_ref;
};

template< typename T >
struct primal_traits<const T*>
{
    typedef  T   primal_t;
    typedef  T   contrary_const_t;
    typedef  T*  contrary_const_ptr;
    typedef  T&  contrary_const_ref;
};

template< typename T >
struct primal_traits<T&>
{
    typedef  T         primal_t;
    typedef  const T   contrary_const_t;
    typedef  const T*  contrary_const_ptr;
    typedef  const T&  contrary_const_ref;
};

template< typename T >
struct primal_traits<const T&>
{
    typedef  T   primal_t;
    typedef  T   contrary_const_t;
    typedef  T*  contrary_const_ptr;
    typedef  T&  contrary_const_ref;
};

//------------------------------------------------------------------------------

struct same_type {};
struct different_type {};

template< typename T1, typename T2 >
struct matching_traits
{
    typedef  different_type  result;
};

template< typename T >
struct matching_traits<T, T>
{
    typedef  same_type  result;
};

//------------------------------------------------------------------------------

template< typename T >
struct move_traits
{
    typedef  false_type  move_ability;
};

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
}  //end namespace
#endif
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -