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

📄 constraints.hpp

📁 用STL的方式封装了WindowsAPI、COM调用、ACE、ATL、MFC、WTL等多种组件
💻 HPP
📖 第 1 页 / 共 2 页
字号:

    // Required by CodeWarrior
    ~must_be_pod() stlsoft_throw_0()
    {
        int   (*pfn)(void) = constraints;

        STLSOFT_SUPPRESS_UNUSED(pfn);
    }

private:
    static int constraints()
    {
#if defined(STLSOFT_COMPILER_IS_MWERKS)
# if ((__MWERKS__ & 0xFF00) < 0x3000)
        class_type  u;
# else /* ? compiler */
        class_type  u;

        u = *static_cast<class_type*>(0);
# endif /* compiler */
#elif defined(STLSOFT_COMPILER_IS_GCC) && \
      __GNUC__ < 3
        class_type  u = *static_cast<class_type*>(0);
#else /* ? compiler */
        class_type  u = class_type();
#endif /* compiler */

        STLSOFT_SUPPRESS_UNUSED(u);

        return sizeof(u);
    }
};


// must_be_pod_or_void
//
/// Constraint to ensure that a type is a built-in or trivial type, or is void.
///
/// \param T The type
// This class can be used to constrain a type to be of either built-in, e.g.
// int, or of a trivial type, i.e. aggregate types or types with publicly
// accessible default contructors and assignment operators
template <ss_typename_param_k T>
union must_be_pod_or_void
{
private:
    typedef must_be_pod_or_void<T>  class_type;

public:
    T   t;
    int i;

    typedef int (*func_ptr_type)();

    static func_ptr_type constraint()
    {
        return constraints;
    }

#if defined(STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR)
protected:
#else /* ? STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR */
private:
#endif /* STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR */
    static int constraints()
    {
        class_type   u;

        u.i = 1;    // CodeWarrior requires this

        STLSOFT_SUPPRESS_UNUSED(u);

        return sizeof(u);
    }
};

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION

STLSOFT_TEMPLATE_SPECIALISATION
union must_be_pod_or_void<void>
{
    typedef int (*func_ptr_type)();

    static func_ptr_type constraint()
    {
        return static_cast<func_ptr_type>(0);   // Can't use NULL here, as Intel C++ gets snippy with NULL_v
    }
};

#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

/* ////////////////////////////////////////////////////////////////////// */

#if 0

/// This type is used as a tag parent to hide implicit comparison of types that
/// provide implicit converion operators.

#ifdef NIC_TEMPLATE_VERSION
//struct nic_null_
//{};

typedef void    nic_null_;

template <ss_typename_param_k T = nic_null_>
struct not_implicitly_comparable
    : public T
{
public:
    typedef not_implicitly_comparable<T>    class_type;

#if defined(STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR)
protected:
#else /* ? STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR */
private:
#endif /* STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR */
#if 0
    template <ss_typename_param_k T2>
    ss_bool_t operator ==(T2 const &) const;
    template <ss_typename_param_k T2>
    ss_bool_t operator !=(T2 const &) const;
#endif /* 0 */
};

/// This specialisation allows it to
STLSOFT_TEMPLATE_SPECIALISATION
struct not_implicitly_comparable<nic_null_>
{
public:
    typedef not_implicitly_comparable<nic_null_>    class_type;

#if defined(STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR)
protected:
#else /* ? STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR */
private:
#endif /* STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR */
#if 0
    template <ss_typename_param_k T2>
    ss_bool_t operator ==(T2 const &) const;
    template <ss_typename_param_k T2>
    ss_bool_t operator !=(T2 const &) const;
#endif /* 0 */
};

template<   ss_typename_param_k T
        ,   ss_typename_param_k T2
        >
inline ss_bool_t operator ==(not_implicitly_comparable<T> const &lhs, T2 const &rhs)
{
//  return lhs.operator ==(rhs);

  lhs.this_type_does_not_support_comparisons();

  return false; // Placate the eager beavers
}

template<   ss_typename_param_k T
        ,   ss_typename_param_k T2
        >
inline ss_bool_t operator ==(T2 const &lhs, not_implicitly_comparable<T> const &rhs)
{
//  return rhs.operator ==(lhs);

  rhs.this_type_does_not_support_comparisons();

  return false; // Placate the eager beavers
}

#if 0
template<   ss_typename_param_k T1
        ,   ss_typename_param_k T2
        >
inline ss_bool_t operator ==(not_implicitly_comparable<T1> const &lhs, not_implicitly_comparable<T2> const &rhs)
{
//  return rhs.operator ==(lhs);

  rhs.this_type_does_not_support_comparisons();

  return false; // Placate the eager beavers
}
#endif /* 0 */

template<   ss_typename_param_k T
        ,   ss_typename_param_k T2
        >
inline ss_bool_t operator !=(T2 const &lhs, not_implicitly_comparable<T> const &rhs)
{
//  return rhs.operator !=(lhs);

  rhs.this_type_does_not_support_comparisons();

  return false; // Placate the eager beavers
}

template<   ss_typename_param_k T
        ,   ss_typename_param_k T2
        >
inline ss_bool_t operator !=(not_implicitly_comparable<T> const &lhs, T2 const &rhs)
{
//  return lhs.operator !=(rhs);

  lhs.this_type_does_not_support_comparisons();

  return false; // Placate the eager beavers
}

template<   ss_typename_param_k T1
        ,   ss_typename_param_k T2
        >
inline ss_bool_t operator !=(not_implicitly_comparable<T1> const &lhs, not_implicitly_comparable<T2> const &rhs)
{
//  return lhs.operator !=(rhs);

  lhs.this_type_does_not_support_comparisons();

  return false; // Placate the eager beavers
}

#else /* ? 0 */

struct not_implicitly_comparable
{
public:
    typedef not_implicitly_comparable   class_type;

#if defined(STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR)
protected:
#else /* ? STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR */
private:
#endif /* STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR */

#ifndef NIC_EXTERNAL_OPERATORS
    ss_bool_t operator ==(class_type const &) const;
    ss_bool_t operator !=(class_type const &) const;

    template <ss_typename_param_k T2>
    ss_bool_t operator ==(T2 const &) const;
    template <ss_typename_param_k T2>
    ss_bool_t operator !=(T2 const &) const;
#endif /* !NIC_EXTERNAL_OPERATORS */
};


#ifdef NIC_EXTERNAL_OPERATORS

template<   ss_typename_param_k T2
        >
inline ss_bool_t operator ==(not_implicitly_comparable const &lhs, T2 const &rhs)
{
//  return lhs.operator ==(rhs);

  lhs.this_type_does_not_support_comparisons();

  return false; // Placate the eager beavers
}

template<   ss_typename_param_k T2
        >
inline ss_bool_t operator ==(T2 const &lhs, not_implicitly_comparable const &rhs)
{
//  return rhs.operator ==(lhs);

  rhs.this_type_does_not_support_comparisons();

  return false; // Placate the eager beavers
}
#endif /* NIC_EXTERNAL_OPERATORS */

#endif /* 0 */
#endif /* 0 */

/* ////////////////////////////////////////////////////////////////////// */

#ifndef _STLSOFT_NO_NAMESPACE
} // namespace stlsoft
#endif /* _STLSOFT_NO_NAMESPACE */

/* ////////////////////////////////////////////////////////////////////// */

#endif /* !STLSOFT_INCL_STLSOFT_HPP_CONSTRAINTS */

/* ////////////////////////////////////////////////////////////////////// */

⌨️ 快捷键说明

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