📄 stlsoft_meta.h
字号:
/* /////////////////////////////////////////////////////////////////////////
* File: stlsoft_meta.h (originally MTBase.h, ::SynesisStl)
*
* Purpose: Meta programming primitives.
*
* Created: 19th November 1998
* Updated: 18th June 2006
*
* Home: http://stlsoft.org/
*
* Copyright (c) 1998-2006, Matthew Wilson and Synesis Software
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
* any contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* ////////////////////////////////////////////////////////////////////// */
/// \file stlsoft_meta.h
///
/// Meta programming primitives.
#ifndef STLSOFT_INCL_H_STLSOFT_META
#define STLSOFT_INCL_H_STLSOFT_META
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define STLSOFT_VER_H_STLSOFT_META_MAJOR 3
# define STLSOFT_VER_H_STLSOFT_META_MINOR 21
# define STLSOFT_VER_H_STLSOFT_META_REVISION 1
# define STLSOFT_VER_H_STLSOFT_META_EDIT 121
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* /////////////////////////////////////////////////////////////////////////
* Includes
*/
#ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
# include <stlsoft/stlsoft.h>
#endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
#ifndef STLSOFT_INCL_STLSOFT_META_HPP_CAPABILITIES
# include <stlsoft/meta/capabilities.hpp>
#endif /* STLSOFT_INCL_STLSOFT_META_HPP_CAPABILITIES */
#ifndef STLSOFT_INCL_STLSOFT_META_UTIL_HPP_META_
# include <stlsoft/meta/util/meta_.hpp>
#endif /* STLSOFT_INCL_STLSOFT_META_UTIL_HPP_META_ */
#ifndef STLSOFT_INCL_STLSOFT_META_HPP_YESNO
# include <stlsoft/meta/yesno.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_META_HPP_YESNO */
#ifndef STLSOFT_INCL_STLSOFT_META_HPP_IS_FUNCTION_POINTER_TYPE
# include <stlsoft/meta/is_function_pointer_type.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_META_HPP_IS_FUNCTION_POINTER_TYPE */
#ifndef STLSOFT_INCL_STLSOFT_META_HPP_IS_INTEGRAL_TYPE
# include <stlsoft/meta/is_integral_type.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_META_HPP_IS_INTEGRAL_TYPE */
#ifndef STLSOFT_INCL_STLSOFT_META_HPP_IS_POINTER_TYPE
# include <stlsoft/meta/is_pointer_type.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_META_HPP_IS_POINTER_TYPE */
#ifndef STLSOFT_INCL_STLSOFT_META_HPP_N_TYPES
# include <stlsoft/meta/n_types.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_META_HPP_N_TYPES */
#ifndef STLSOFT_INCL_STLSOFT_META_HPP_IS_SAME_TYPE
# include <stlsoft/meta/is_same_type.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_META_HPP_IS_SAME_TYPE */
#ifndef STLSOFT_INCL_STLSOFT_META_HPP_SELECT_FIRST_TYPE_IF
# include <stlsoft/meta/select_first_type_if.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_META_HPP_SELECT_FIRST_TYPE_IF */
#ifndef STLSOFT_INCL_STLSOFT_META_HPP_SIZEOF
# include <stlsoft/meta/size_of.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_META_HPP_SIZEOF */
/* /////////////////////////////////////////////////////////////////////////
* Namespace
*/
#ifndef _STLSOFT_NO_NAMESPACE
namespace stlsoft
{
#endif /* _STLSOFT_NO_NAMESPACE */
/* /////////////////////////////////////////////////////////////////////////
* Tests
*/
// is_array_type
//
/// Constraint to ensure that a type is a pointer type
template <ss_typename_param_k U>
one_t is_array_type_func(U const volatile *);
two_t is_array_type_func(...);
/// traits type used to determine whether the given type is an array
template <ss_typename_param_k T>
struct is_array_type
{
typedef T test_type;
private:
static T t;
public:
enum { value = sizeof(is_array_type_func(t)) == sizeof(one_t) };
};
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
STLSOFT_TEMPLATE_SPECIALISATION
struct is_array_type<void>
{
enum { value = 0 };
};
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
// is_convertible_to_pointer
//
/// This test determines whether the given type is convertible to a pointer
/// type
template <ss_typename_param_k T>
struct is_convertible_to_pointer
{
};
// is_convertible_to_bool
//
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
template <ss_typename_param_k T>
struct convertible_index
{
// typedef <size_type> type;
};
STLSOFT_TEMPLATE_SPECIALISATION
struct convertible_index<int>
{
typedef size_type<2> type;
};
STLSOFT_TEMPLATE_SPECIALISATION
struct convertible_index<unsigned>
{
typedef size_type<3> type;
};
#ifdef STLSOFT_CF_NATIVE_BOOL_SUPPORT
STLSOFT_TEMPLATE_SPECIALISATION
struct convertible_index<bool>
{
typedef size_type<4> type;
};
#endif /* STLSOFT_CF_NATIVE_BOOL_SUPPORT */
STLSOFT_TEMPLATE_SPECIALISATION
struct convertible_index<void*>
{
typedef size_type<5> type;
};
STLSOFT_TEMPLATE_SPECIALISATION
struct convertible_index<long double>
{
typedef size_type<6> type;
};
size_type<1> convertible_index_function(...);
//convertible_index<int>::type convertible_index_function(int );
//convertible_index<unsigned>::type convertible_index_function(unsigned );
# ifdef STLSOFT_COMPILER_IS_MSVC
convertible_index<int>::type convertible_index_function(int );
convertible_index<int>::type convertible_index_function(unsigned int );
convertible_index<int>::type convertible_index_function(long );
convertible_index<int>::type convertible_index_function(unsigned long );
convertible_index<long double>::type convertible_index_function(double );
convertible_index<long double>::type convertible_index_function(long double );
# endif /* compiler */
# ifdef STLSOFT_CF_NATIVE_BOOL_SUPPORT
convertible_index<bool>::type convertible_index_function(bool );
# endif /* STLSOFT_CF_NATIVE_BOOL_SUPPORT */
convertible_index<void*>::type convertible_index_function(void const volatile* );
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/// This test determines whether the given type is convertible to a pointer
/// type
template <ss_typename_param_k T>
struct is_convertible_to_bool
{
enum { value = sizeof(convertible_index_function(*static_cast<T*>(0))) == sizeof(convertible_index<bool>::type) };
};
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
STLSOFT_TEMPLATE_SPECIALISATION
struct is_convertible_to_bool<void>
{
enum { value = 0 };
};
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/// traits type used to determine whether the given type is a numeric type
template <ss_typename_param_k T>
struct is_numeric_type
{
enum { value = 0 };
};
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
STLSOFT_GEN_TRAIT_SPECIALISATION(is_numeric_type, ss_sint8_t, 1)
STLSOFT_GEN_TRAIT_SPECIALISATION(is_numeric_type, ss_uint8_t, 1)
STLSOFT_GEN_TRAIT_SPECIALISATION(is_numeric_type, ss_sint16_t, 1)
STLSOFT_GEN_TRAIT_SPECIALISATION(is_numeric_type, ss_uint16_t, 1)
STLSOFT_GEN_TRAIT_SPECIALISATION(is_numeric_type, ss_sint32_t, 1)
STLSOFT_GEN_TRAIT_SPECIALISATION(is_numeric_type, ss_uint32_t, 1)
#ifdef STLSOFT_CF_64BIT_INT_SUPPORT
STLSOFT_GEN_TRAIT_SPECIALISATION(is_numeric_type, ss_sint64_t, 1)
STLSOFT_GEN_TRAIT_SPECIALISATION(is_numeric_type, ss_uint64_t, 1)
#endif /* STLSOFT_CF_64BIT_INT_SUPPORT */
#if ( defined(STLSOFT_COMPILER_IS_INTEL) || \
defined(STLSOFT_COMPILER_IS_MSVC)) && \
_MSC_VER == 1200
STLSOFT_GEN_TRAIT_SPECIALISATION(is_numeric_type, signed char, 1)
STLSOFT_GEN_TRAIT_SPECIALISATION(is_numeric_type, unsigned char, 1)
STLSOFT_GEN_TRAIT_SPECIALISATION(is_numeric_type, signed short, 1)
STLSOFT_GEN_TRAIT_SPECIALISATION(is_numeric_type, unsigned short, 1)
STLSOFT_GEN_TRAIT_SPECIALISATION(is_numeric_type, signed int, 1)
STLSOFT_GEN_TRAIT_SPECIALISATION(is_numeric_type, unsigned int, 1)
STLSOFT_GEN_TRAIT_SPECIALISATION(is_numeric_type, signed long, 1)
STLSOFT_GEN_TRAIT_SPECIALISATION(is_numeric_type, unsigned long, 1)
#elif defined(STLSOFT_CF_INT_DISTINCT_TYPE)
STLSOFT_GEN_TRAIT_SPECIALISATION(is_numeric_type, signed int, 1)
STLSOFT_GEN_TRAIT_SPECIALISATION(is_numeric_type, unsigned int, 1)
#endif /* _MSC_VER == 1200 */
STLSOFT_GEN_TRAIT_SPECIALISATION(is_numeric_type, float, 1)
STLSOFT_GEN_TRAIT_SPECIALISATION(is_numeric_type, double, 1)
STLSOFT_GEN_TRAIT_SPECIALISATION(is_numeric_type, long double, 1)
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/// traits type used to determine whether a given type is signed
template <ss_typename_param_k T>
struct is_signed_type
{
enum { value = 0 };
typedef no_type type;
};
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
STLSOFT_GEN_TRAIT_SPECIALISATION_WITH_TYPE(is_signed_type, ss_sint8_t, 1, yes_type)
STLSOFT_GEN_TRAIT_SPECIALISATION_WITH_TYPE(is_signed_type, ss_sint16_t, 1, yes_type)
STLSOFT_GEN_TRAIT_SPECIALISATION_WITH_TYPE(is_signed_type, ss_sint32_t, 1, yes_type)
#ifdef STLSOFT_CF_64BIT_INT_SUPPORT
STLSOFT_GEN_TRAIT_SPECIALISATION_WITH_TYPE(is_signed_type, ss_sint64_t, 1, yes_type)
#endif /* STLSOFT_CF_64BIT_INT_SUPPORT */
#if ( defined(STLSOFT_COMPILER_IS_INTEL) || \
defined(STLSOFT_COMPILER_IS_MSVC)) && \
_MSC_VER == 1200
STLSOFT_GEN_TRAIT_SPECIALISATION_WITH_TYPE(is_signed_type, signed char, 1, yes_type)
STLSOFT_GEN_TRAIT_SPECIALISATION_WITH_TYPE(is_signed_type, signed short, 1, yes_type)
STLSOFT_GEN_TRAIT_SPECIALISATION_WITH_TYPE(is_signed_type, signed int, 1, yes_type)
STLSOFT_GEN_TRAIT_SPECIALISATION_WITH_TYPE(is_signed_type, signed long, 1, yes_type)
#elif defined(STLSOFT_CF_INT_DISTINCT_TYPE)
STLSOFT_GEN_TRAIT_SPECIALISATION_WITH_TYPE(is_signed_type, signed int, 1, yes_type)
#endif /* _MSC_VER == 1200 */
STLSOFT_GEN_TRAIT_SPECIALISATION_WITH_TYPE(is_signed_type, float, 1, yes_type)
STLSOFT_GEN_TRAIT_SPECIALISATION_WITH_TYPE(is_signed_type, double, 1, yes_type)
STLSOFT_GEN_TRAIT_SPECIALISATION_WITH_TYPE(is_signed_type, long double, 1, yes_type)
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/// traits type used to determine whether the given type is floating point
template <ss_typename_param_k T>
struct is_floating_point_type
{
enum { value = 0 };
};
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
STLSOFT_GEN_TRAIT_SPECIALISATION(is_floating_point_type, float, 1)
STLSOFT_GEN_TRAIT_SPECIALISATION(is_floating_point_type, double, 1)
STLSOFT_GEN_TRAIT_SPECIALISATION(is_floating_point_type, long double, 1)
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/// traits type used to determine whether the given type is of char type
template <ss_typename_param_k T>
struct is_char_type
{
enum { value = 0 };
};
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
STLSOFT_GEN_TRAIT_SPECIALISATION(is_char_type, char, 1)
STLSOFT_GEN_TRAIT_SPECIALISATION(is_char_type, wchar_t, 1)
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/// traits type used to determine whether the given type is \c bool
template <ss_typename_param_k T>
struct is_bool_type
{
enum { value = 0 };
};
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
STLSOFT_GEN_TRAIT_SPECIALISATION(is_bool_type, ss_bool_t, 1)
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/// traits type used to determine whether a given type is \c void
template <ss_typename_param_k T>
struct is_void_type
{
enum { value = 0 };
};
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
STLSOFT_GEN_TRAIT_SPECIALISATION(is_void_type, void, 1)
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/// traits type used to determine whether a given type is a fundamental type
template <ss_typename_param_k T>
struct is_fundamental_type
{
enum
{
value = is_integral_type<T>::value
|| is_floating_point_type<T>::value
|| is_bool_type<T>::value
|| is_void_type<T>::value
};
#ifdef STLSOFT_META_HAS_SELECT_FIRST_TYPE_IF
typedef ss_typename_type_k select_first_type_if<yes_type, no_type, value>::type type;
#endif /* STLSOFT_META_HAS_SELECT_FIRST_TYPE_IF */
};
/// traits type used to determine whether a given type is a compound type
template <ss_typename_param_k T>
struct is_compound_type
{
enum { value = (0 == is_fundamental_type<T>::value) };
};
// is_class_type
/// Compatibility
///
/// Borland C/C++ 5.6 compiles but thinks everything is a class type
/// CodePlay compiles but thinks that nothing is a class type
/// Comeau works with most things (not references)
/// CodeWarrior 3.0+ compiles and works from version 8 onwards
/// Digital Mars 8.40+ compiles and works with most things (not references)
/// GCC works with most things (not references)
/// Intel works with most things (not references)
/// Visual C++ compiles and works from version 7.1 onwards with most things (not references)
#if ( !defined(STLSOFT_COMPILER_IS_MWERKS) || \
(__MWERKS__ & 0xFF00) >= 0x3000) && \
( !defined(STLSOFT_COMPILER_IS_MSVC) || \
_MSC_VER >= 1100) && \
!defined(STLSOFT_COMPILER_IS_WATCOM)
template <ss_typename_param_k C>
one_t is_class_type_func(int C::*);
template <ss_typename_param_k C>
two_t is_class_type_func(...);
/// traits type used to determine whether a given type is of class type
template <ss_typename_param_k T>
struct is_class_type
{
typedef T test_type;
enum { value = sizeof(is_class_type_func<test_type>(0)) == sizeof(one_t) };
};
#endif /* compiler */
// is_const
#if defined(STLSOFT_COMPILER_IS_MWERKS)
one_t is_const_type_func(void const *);
two_t is_const_type_func(void *);
#else /* ? compiler */
one_t is_const_type_func(void volatile const *);
two_t is_const_type_func(void volatile *);
#endif /* compiler */
two_t is_const_type_func(...);
/// traits type used to determine whether a given type is \c const
template <ss_typename_param_k T>
struct is_const
{
typedef T test_type;
private:
static T t;
public:
enum { value = sizeof(is_const_type_func(&t)) == sizeof(one_t) };
};
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
STLSOFT_TEMPLATE_SPECIALISATION
struct is_const<void>
{
typedef void test_type;
enum { value = 0 };
};
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
// is_volatile
one_t is_volatile_type_func(void const volatile *);
two_t is_volatile_type_func(void const *);
two_t is_volatile_type_func(...);
/// traits type used to determine whether a given type has volatile qualifier
template <ss_typename_param_k T>
struct is_volatile
{
typedef T test_type;
private:
static T t;
public:
enum { value = sizeof(is_volatile_type_func(&t)) == sizeof(one_t) };
};
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
STLSOFT_TEMPLATE_SPECIALISATION
struct is_volatile<void>
{
typedef void test_type;
enum { value = 0 };
};
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/// traits type used to determine whether a given type is \c void
template <ss_typename_param_k T>
struct is_void
{
enum { value = 0 };
};
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
STLSOFT_TEMPLATE_SPECIALISATION
struct is_void<void>
{
enum { value = 1 };
};
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
#if !defined(STLSOFT_COMPILER_IS_BORLAND) && \
( !defined(STLSOFT_COMPILER_IS_DMC) || \
__DMC__ >= 0x0845) && \
( !defined(STLSOFT_COMPILER_IS_MSVC) || \
_MSC_VER >= 1310) && \
!defined(STLSOFT_COMPILER_IS_VECTORC) && \
!defined(STLSOFT_COMPILER_IS_WATCOM)
# define STLSOFT_CF_HAS_MEMBER_TYPE_SUPPORTED
// has_value_type
template <ss_typename_param_k T>
one_t has_value_type_function(...);
template <ss_typename_param_k T>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -