注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

一路

To find the final symmetry & beauty

 
 
 

日志

 
 
 
 

SGI STL源码文件concept_check.h (注释)  

2011-02-15 14:58:08|  分类: 默认分类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

 

 

/ *

* Copyright (c) 1999

* Silicon Graphics Computer Systems, Inc.

*

* Permission to use, copy, modify, distribute and sell this software

* and its documentation 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. Silicon Graphics makes no

* representations about the suitability of this software for any

* purpose. It is provided "as is" without express or implied warranty.

*/

 

#ifndef CONCEPT_CHECKS_H

#define CONCEPT_CHECKS_H

 

/ *

Use these macro like assertions, but they assert properties

on types (usually template arguments). In technical terms they verify whether a type "models" a "concept".

 

This set of requirements and the terminology used here is derived from the book "Generic Programming and the STL" by Matt Austern (Addison Wesley). For further information please consult that

book. The requirements also are intended to match the ANSI/ ISO C++

standard.

 

This file covers the basic concepts and the iterator concepts. There are several other files that provide the requirements for the STL containers:

container_concepts.h sequence_concepts.h assoc_container_concepts.h

 

Jeremy Siek, 1999

 

TO DO:

- some issues with regards to concept classification and mutability including AssociativeContianer - > ForwardContainer

and SortedAssociativeContainer - > ReversibleContainer

- HashedAssociativeContainer

- Allocator

- Function Object Concepts

 

*/

 

#ifndef STL_USE_CONCEPT_CHECKS

 

/ / Some compilers lack the features that are necessary for concept checks.

/ / On those compilers we define the concept check macros to do nothing.

#define STL_REQUIRES( type_var, concept) do {} while(0)

#define STL_CLASS_REQUIRES( type_var, concept) \

static int     ## type_var##_## concept

#define STL_CONVERTIBLE( type_x, type_y) do {} while(0)

#define STL_REQUIRES_SAME_TYPE( type_x, type_y) do {} while(0)

#define STL_CLASS_REQUIRES_SAME_TYPE( type_x, type_y) \

static int     ## type_x## type_y##_require_same_type

 

 

 

#define STL_GENERATOR_CHECK( func, ret) do {} while(0)

#define STL_CLASS_GENERATOR_CHECK( func, ret) \

static int     ## func## ret##_generator_check

#define STL_UNARY_FUNCTION_CHECK( func, ret, arg) do {} while(0)

#define STL_CLASS_UNARY_FUNCTION_CHECK( func, ret, arg) \

static int     ## func## ret## arg##_unary_function_check

#define STL_BINARY_FUNCTION_CHECK( func, ret, first, second) \

do {} while(0)

#define STL_CLASS_BINARY_FUNCTION_CHECK( func, ret, first,

second) \

static int     ## func## ret## first## second##

_binary_function_check

#define STL_REQUIRES_BINARY_OP( opname, ret, first, second) \

do {} while(0)

#define STL_CLASS_REQUIRES_BINARY_OP( opname, ret, first,

second) \

static int ## opname## ret## first## second##_require_binary_op

 

#else / *     STL_USE_CONCEPT_CHECKS */

 

/ / This macro tests whether the template argument "     type_var"

/ / satisfies the requirements of "     concept". Here is a list of concepts

/ / that we know how to check:

/ /    _Allocator

/ /    _Assignable

/ /    _DefaultConstructible

/ /    _EqualityComparable

/ /    _LessThanComparable

/ /    _TrivialIterator

/ /    _InputIterator

/ /    _OutputIterator

/ /    _ForwardIterator

/ /    _BidirectionalIterator

/ /    _RandomAccessIterator

/ /    _Mutable_TrivialIterator

/ /    _Mutable_ForwardIterator

/ /    _Mutable_BidirectionalIterator

/ /    _Mutable_RandomAccessIterator

 

#define STL_REQUIRES( type_var, concept) \

do { \

void (* x)( type_var ) = concept##_concept_specification<

type_var >\

:: concept##_requirement_violation; __x = __x; } while (0)

 

/ / Use this to check whether type X is convertible to type Y

#define STL_CONVERTIBLE( type_x, type_y) \

do { \

void (* x)( type_x , type_y ) = _STL_CONVERT_ERROR< type_x , \

type_y >:: type_X_is_not_convertible_to_type_Y; \

x = x; } while (0)

 

/ / Use this to test whether two template arguments are the same type

#define STL_REQUIRES_SAME_TYPE( type_x, type_y) \

do { \

void (* x)( type_x , type_y ) = _STL_SAME_TYPE_ERROR< type_x, \

type_y    >:: type_X_not_same_as_type_Y; \

x = x; } while (0)

 

 

 

 

/ / function object checks

#define STL_GENERATOR_CHECK( func, ret) \

do { \

ret (* x)( func&) = \

_STL_GENERATOR_ERROR< \

func, ret>:: generator_requirement_violation; \

x = x; } while (0)

 

 

#define STL_UNARY_FUNCTION_CHECK( func, ret, arg) \

do { \

ret (* x)( func&, const arg& ) = \

_STL_UNARY_FUNCTION_ERROR< \

func, ret, arg>:: unary_function_requirement_violation; \

x = x; } while (0)

 

 

#define STL_BINARY_FUNCTION_CHECK( func, ret, first, second) \

do { \

ret (* x)( func&, const first&, const second& ) = \

_STL_BINARY_FUNCTION_ERROR< \

func, ret, first, second>::

binary_function_requirement_violation; \

x = x; } while (0)

 

 

#define STL_REQUIRES_BINARY_OP( opname, ret, first, second) \

do { \

ret (* x)( first&, second& ) = _STL_BINARY## opname##_ERROR< \

ret, first, second>:: binary_operator_requirement_violation;

\

ret (* y)( const first&, const second& ) = \

_STL_BINARY## opname##_ERROR< ret, first, second>:: \

const_binary_operator_requirement_violation; \

y = y; x = x; } while (0)

 

 

#ifdef STL_NO_FUNCTION_PTR_IN_CLASS_TEMPLATE

 

#define STL_CLASS_REQUIRES( type_var, concept)

#define STL_CLASS_REQUIRES_SAME_TYPE( type_x, type_y)

#define STL_CLASS_GENERATOR_CHECK( func, ret)

#define STL_CLASS_UNARY_FUNCTION_CHECK( func, ret, arg)

#define STL_CLASS_BINARY_FUNCTION_CHECK( func, ret, first,

second)

#define STL_CLASS_REQUIRES_BINARY_OP( opname, ret, first,

second)

 

#else

 

/ / Use this macro inside of template classes, where you would

/ / like to place requirements on the template arguments to the class

/ / Warning: do not pass pointers and such (e.g. T*) in as the     type_var,

/ / since the type_var is used to construct identifiers. Instead typedef

/ / the pointer type, then use the typedef name for the     type_var.

#define STL_CLASS_REQUIRES( type_var, concept) \

typedef void (* func## type_var## concept)( type_var ); \

template < func## type_var## concept _Tp1> \

 

 

 

struct dummy_struct_## type_var## concept { }; \

static dummy_struct_## type_var## concept< \

concept##_concept_specification< \

type_var>:: concept##_requirement_violation>    \

dummy_ptr_## type_var## concept

 

 

#define STL_CLASS_REQUIRES_SAME_TYPE( type_x, type_y) \

typedef void (* func_## type_x## type_y##same_type)( type_x, \

type_y );

\

template < func_## type_x## type_y##same_type _Tp1> \

struct dummy_struct_## type_x## type_y##_same_type { }; \

static dummy_struct_## type_x## type_y##_same_type< \

_STL_SAME_TYPE_ERROR< type_x, type_y>::

type_X_not_same_as_type_Y>    \

dummy_ptr_## type_x## type_y##_same_type

 

 

#define STL_CLASS_GENERATOR_CHECK( func, ret) \

typedef ret (* f_## func## ret##_generator)( func& ); \

template < f_## func## ret##_generator _Tp1> \

struct dummy_struct_## func## ret##_generator { }; \

static dummy_struct_## func## ret##_generator< \

_STL_GENERATOR_ERROR< \

func, ret>:: generator_requirement_violation>    \

dummy_ptr_## func## ret##_generator

 

 

#define STL_CLASS_UNARY_FUNCTION_CHECK( func, ret, arg) \

typedef ret (* f_## func## ret## arg##_unary_check)( func&, \

const arg& );

\

template < f_## func## ret## arg##_unary_check _Tp1> \

struct dummy_struct_## func## ret## arg##_unary_check { }; \

static dummy_struct_## func## ret## arg##_unary_check< \

_STL_UNARY_FUNCTION_ERROR< \

func, ret, arg>:: unary_function_requirement_violation>    \

dummy_ptr_## func## ret## arg##_unary_check

 

 

#define STL_CLASS_BINARY_FUNCTION_CHECK( func, ret, first,

second) \

typedef ret (* f_## func## ret## first## second##_binary_check

)( func&, const first&,\

const second& ); \

template < f_## func## ret## first## second##_binary_check _Tp1>

\

struct dummy_struct_## func## ret## first## second##

_binary_check { }; \

static dummy_struct_## func## ret## first## second##

_binary_check< \

_STL_BINARY_FUNCTION_ERROR< func, ret, first, second>:: \

binary_function_requirement_violation>    \

dummy_ptr_## func## ret## first## second##_binary_check

 

 

 

second) \

typedef ret (* f_## func## ret## first## second##_binary_op)(

const first&, \

const second& ); \ template < f_## func## ret## first## second##_binary_op _Tp1> \ struct dummy_struct_## func## ret## first## second##_binary_op {

}; \

static dummy_struct_## func## ret## first## second##_binary_op<

\

_STL_BINARY## opname##_ERROR< ret, first, second>:: \

binary_operator_requirement_violation>    \

dummy_ptr_## func## ret## first## second##_binary_op

 

#endif

 

/ * helper class for finding non- const version of a type. Need to have something to assign to etc. when testing constant iterators. */

//去取const的简单trait

template <class _Tp>

struct _Mutable_trait {

typedef _Tp _Type;

};

template <class _Tp>

struct _Mutable_trait<const _Tp> {

typedef _Tp _Type;

};

 

 

/ * helper function for avoiding compiler warnings about unused variables */

template <class _Type>

 

 

void

__sink_unused_warning(_Type) { }

 

 

 

template <class _TypeX, class _TypeY>

struct _STL_CONVERT_ERROR {

static void

__type_X_is_not_convertible_to_type_Y(_TypeX

_TypeY y = x;

sink_unused_warning( y);

 

 

 

 

 

__x,

 

 

 

 

 

_TypeY) {

 

}

};

 

 

 

 

template <class

 

_Type> struct

__check_equal { };

 

 

 

template <class _TypeX, class _TypeY>

struct _STL_SAME_TYPE_ERROR {

static void

__type_X_not_same_as_type_Y(_TypeX ,

 

 

 

 

 

_TypeY ) {

 

check_equal<_TypeX> t1 = check_equal<_TypeY>();

}

};

 

 

/ / Some Functon Object Checks

 

 

 

template <class _Func, class _Ret>

struct _STL_GENERATOR_ERROR {

 

 

static

 

_Ret

__generator_requirement_violation(_Func&

 

__f) {

 

return f();

}

};

 

template <class _Func>

struct _STL_GENERATOR_ERROR<_Func, void> {

 

 

static void

f();

__generator_requirement_violation(_Func&

 

__f) {

 

}

};

 

 

 

template <class _Func, class _Ret, class _Arg>

struct _STL_UNARY_FUNCTION_ERROR {

static _Ret

__unary_function_requirement_violation(_Func&

 

 

 

 

 

__f,

 

 

return f( arg);

}

};

const _Arg& arg) {

 

 

template <class _Func, class _Arg>

struct _STL_UNARY_FUNCTION_ERROR<_Func, void, _Arg> {

static void

 

__unary_function_requirement_violation(_Func&

 

__f,

 

 

f( arg);

}

};

const _Arg& arg) {

 

 

template <class _Func, class _Ret, class _First, class _Second>

struct _STL_BINARY_FUNCTION_ERROR {

static _Ret

 

__binary_function_requirement_violation(_Func&

 

__f,

 

 

 

 

return f( first, second);

}

};

const _First& first, const _Second& second) {

 

 

template <class _Func, class _First, class _Second>

struct _STL_BINARY_FUNCTION_ERROR<_Func, void, _First,

_Second> {

static void

 

__binary_function_requirement_violation(_Func&

 

__f,

 

 

 

 

f( first, second);

}

};

const _First& first, const _Second& second) {

 

 

 

 

#define STL_DEFINE_BINARY_OP_CHECK(_OP, _NAME) \ template <class _Ret, class _First, class _Second> \ struct _STL_BINARY##_NAME##_ERROR { \

static _Ret \

const_binary_operator_requirement_violation(const _First& first,

 

\

 

{ \

return first _OP second; \

} \

static _Ret \

 

const _Second& second)

 

binary_operator_requirement_violation(_First& __first,    \

 

 

return first _OP second; \

} \

}

_Second&

__second) { \

 

 

__STL_DEFINE_BINARY_OP_CHECK(==, _OP_EQUAL);

STL_DEFINE_BINARY_OP_CHECK(!=, _OP_NOT_EQUAL);

__STL_DEFINE_BINARY_OP_CHECK(<, _OP_LESS_THAN);

__STL_DEFINE_BINARY_OP_CHECK(<=, _OP_LESS_EQUAL);

__STL_DEFINE_BINARY_OP_CHECK(>, _OP_GREATER_THAN);

 

__STL_DEFINE_BINARY_OP_CHECK(>=,

 

_OP_GREATER_EQUAL);

 

__STL_DEFINE_BINARY_OP_CHECK(+, _OP_PLUS);

 

__STL_DEFINE_BINARY_OP_CHECK(*,

 

_OP_TIMES);

 

__STL_DEFINE_BINARY_OP_CHECK(/, _OP_DIVIDE);

__STL_DEFINE_BINARY_OP_CHECK(-, _OP_SUBTRACT);

__STL_DEFINE_BINARY_OP_CHECK(%, _OP_MOD);

/ / ...

 

/ / TODO, add unary operators (prefix and postfix)

 

/ *

The presence of this class is just to trick EDG into displaying these error messages before any other errors. Without the classes, the errors in the functions get reported after

other class errors deep inside the library. The name choice just makes for an eye catching error message :)

*/

//EDG公司本身并不生产编译器,他们只开发编译器组件,编译器开发公司够买他们的组件来完成自己的产品 ,其中intelicc就用了这个EDG前端组件

 

//_STL_ERROR这个类中定义了各种错误,所有的错误类型都是使用了静态函数模版,注意其所有函数的后缀处少数几个外都是requirement_violation,这些静态函数名起的特别是为了能在出错时以函数名的方式提示出错信息,因为C++本身并没有自定义出错信息的功能,这种方式也算是一种comprimise,请记住这个后缀,在其它地方有相似的后缀,极易搞混。

struct _STL_ERROR {

 

//此函数查看是否有默认public构造函数,非public的默认构造函数不能直接调用,以后类似不再提示

template <class _Type>

static _Type

__default_constructor_requirement_violation(_Type) {

return _Type();

 

}

//此函数查看是否有赋值运算符

template <class _Type>

static _Type

__assignment_operator_requirement_violation(_Type

a = a;

return a;

 

 

 

 

__a) {

 

}

//此函数查看是否有复制构造函数

template <class _Type>

 

static _Type

__copy_constructor_requirement_violation(_Type

_Type c( a);

return c;

 

 

__a) {

 

}

//此函数查看复制构造函数是否可接受常量引用

template <class _Type>

static _Type

__const_parameter_required_for_copy_constructor(_Type

/ *     a */ ,

 

 

_Type c( b);

return c;

}

//此函数查看赋值操作符是否可接受常量引用

const _Type& b) {

 

template <class _Type>

static _Type

__const_parameter_required_for_assignment_operator(

_Type a,

 

 

a = b;

return a;

}

//此函数查看是否有小于可比较的,这里的小于不是狭意的小于,是一种对偏序关系的描述

const _Type& b) {

 

template <class _Type>

static _Type

__less_than_comparable_requirement_violation(_Type

_Type b) {

 

 

 

__a,

 

if ( a < b || a > b || a <= b || a >= b) return a;

return b;

}

 

//此函数查看类型是否有相等关系

template <class _Type>

static _Type

__equality_comparable_requirement_violation(_Type

_Type b) {

if ( a == b || a != b) return a;

return b;

 

 

 

__a,

 

}

//此函数查看类型是否支持解引用操作,明显是迭代器类型才支持这类操作

template <class _Iterator>

static void

__dereference_operator_requirement_violation(_Iterator

) {

 

 

 

 

__i

 

sink_unused_warning(* i);

}

//此函数查看是否支持解引用操作和解引用后的赋值操作

template <class _Iterator>

static void

 

 

__dereference_operator_and_assignment_requirement_viola

tion(_Iterator i) {

* i = * i;

}

//引函数查看类型是否支持前置自增运算符

template <class _Iterator>

static void

__preincrement_operator_requirement_violation(_Iterator

i) {

++ i;

}

//此函数查看类型是否支持前置自减运算符

template <class _Iterator>

static void

__predecrement_operator_requirement_violation(_Iterator

i) {

-- i;

}

//此函数查看类型是否支持后置自减运算符

template <class _Iterator>

static void

__postdecrement_operator_requirement_violation(_Iterator

i) {

i--;

}

//此函数查看类型是否支持后置自增运算符

template <class _Iterator, class _Type>

static void

 

 

__postincrement_operator_and_assignment_requirement_vi

olation(_Iterator i,

 

 

t) {

* i++ = t;

_Type

 

}

//此函数查看类型是否支持加n并赋值运算,当然一般是random access iterator 有这种运算

template <class _Iterator, class _Distance>

static _Iterator

__iterator_addition_assignment_requirement_violation(

_Iterator i,

 

 

i += n;

return i;

}

//此函数查看类型是否支持加n并赋值,其中加n分为前加和后加

_Distance n) {

 

template <class _Iterator, class _Distance>

static _Iterator

__iterator_addition_requirement_violation(_Iterator

_Distance n) {

i = i + n;

i = n + i;

return i;

 

 

 

__i,

 

}

//与加法类似,此处查看是否支持减法运算

template <class _Iterator, class _Distance>

static _Iterator

__iterator_subtraction_assignment_requirement_violation(

_Iterator i,

 

 

{

i -= n;

return i;

}

//此处与加法对应处类似

_Distance n)

 

template <class _Iterator, class _Distance>

static _Iterator

 

 

 

_Distance n) {

i = i - n;

return i;

 

}

//此数查看迭代器之前的减运算

template <class _Iterator, class _Distance>

static _Distance

__difference_operator_requirement_violation(_Iterator

_Iterator j,

 

 

 

 

__i,

 

 

n = i - j;

return n;

}

//此处查看对类似数组式的读取元素的支持

_Distance n) {

 

template <class _Exp, class _Type, class _Distance>

static _Type

__element_access_operator_requirement_violation(_Exp

, _Type*,

 

 

 

__x

 

 

return x[ n];

}

//此处查看读取元素并赋值的支持

_Distance n) {

 

template <class _Exp, class _Type, class _Distance>

static void

__element_assignment_operator_requirement_violation(

_Exp x,

 

 

 

 

x[ n] = * t;

}

_Type* t,

_Distance n) {

 

 

} ? end _STL_ERROR ? ; / * _STL_ERROR */

 

/ * Associated Type Requirements */

//此处是对各和内部类型定义的检查,这些内部类型是C++标准规范过的,可以看到其中使用了另外一

 

个中间层,这就是traits,使用traits可以带来非常多的好处,关于traits技术可以查看我以后的日志或

 

是在网上google搜索它。如果类型本身没有定义这些内置类型就会出错,这也就达到了检查相应的

 

内部类型定义的目地。

STL_BEGIN_NAMESPACE

template <class _Iterator> struct iterator_traits;

STL_END_NAMESPACE

 

template <class _Iter>

struct value_type_type_definition_requirement_violation {

typedef typename STD::iterator_traits<_Iter>::value_type value_type;

};

 

template <class _Iter>

 

struct

__difference_type_type_definition_requirement_violation {

typedef typename STD::iterator_traits<_Iter>::difference_type

difference_type;

};

 

template <class _Iter>

 

 

struct

__reference_type_definition_requirement_violation {

 

typedef typename STD::iterator_traits<_Iter>::reference reference;

};

 

template <class _Iter>

 

 

 

 

 

struct

__pointer_type_definition_requirement_violation {

 

typedef typename STD::iterator_traits<_Iter>::pointer pointer;

};

 

template <class _Iter>

 

struct

__iterator_category_type_definition_requirement_violation {

typedef typename STD::iterator_traits<_Iter>::iterator_category

iterator_category;

};

 

/ * Assignable Requirements */

 

//这里是测试类型是否符合assignable的规范,符合这个规范的类型要有赋值运算符和

 

复制构造函数,并且赋值运算符和复制构造函数要接收常量引用(这个规定还是很强

 

的,不知为啥这么规定,估计可能是排处auto_ptr这类东西吧,

 

auto_ptr已被新的C++标准认为是废弃的,已不推荐使用了。

 

template <class _Type>

struct _Assignable_concept_specification {

 

 

static void

_Assignable_requirement_violation(_Type

 

__a) {

 

_STL_ERROR:: assignment_operator_requirement_violation( a);

_STL_ERROR:: copy_constructor_requirement_violation( a);

_STL_ERROR:: const_parameter_required_for_copy_constructor( a, a)

;

_STL_ERROR:: const_parameter_required_for_assignment_operator( a,

a);

}

};

 

/ * DefaultConstructible Requirements */

 

//此处查看类型是否是可被默认构造的,是否符合default constructible规范

template <class _Type>

struct _DefaultConstructible_concept_specification {

static void _DefaultConstructible_requirement_violation(

_Type a) {

_STL_ERROR:: default_constructor_requirement_violation( a);

}

};

 

/ * EqualityComparable Requirements */

//此处检查类型是 否符合相等比较规范

template <class _Type>

struct _EqualityComparable_concept_specification {

static void _EqualityComparable_requirement_violation(

_Type a) {

_STL_ERROR:: equality_comparable_requirement_violation( a, a);

}

};

 

/ * LessThanComparable Requirements */

//此处检查是否符合偏序比较规范

template <class _Type>

 

 

 

struct _LessThanComparable_concept_specification {

static void _LessThanComparable_requirement_violation(

_Type a) {

_STL_ERROR:: less_than_comparable_requirement_violation( a, a);

}

};

 

/ * TrivialIterator Requirements */

 

//此处检查是否符合简单迭代器规范

template <class _TrivialIterator>

struct _TrivialIterator_concept_specification {

static void

_TrivialIterator_requirement_violation(_TrivialIterator

typedef typename

 

 

 

 

 

__i) {

 

value_type_type_definition_requirement_violation<_TrivialIterator>

::

value_type T;

/ / Refinement of Assignable

_Assignable_concept_specification<_TrivialIterator>::

_Assignable_requirement_violation( i);

/ / Refinement of DefaultConstructible

_DefaultConstructible_concept_specification<_TrivialIterator>::

_DefaultConstructible_requirement_violation( i);

/ / Refinement of EqualityComparable

_EqualityComparable_concept_specification<_TrivialIterator>::

_EqualityComparable_requirement_violation( i);

/ / Valid Expressions

_STL_ERROR:: dereference_operator_requirement_violation( i);

}

} ? end _TrivialIterator_concept_specification ? ;

//此处检查是否是符合可修改的简单迭代器规范,这是对简单迭代器的refinement

template <class _TrivialIterator>

struct _Mutable_TrivialIterator_concept_specification {

static void

_Mutable_TrivialIterator_requirement_violation(

_TrivialIterator i) {

_TrivialIterator_concept_specification<_TrivialIterator>::

_TrivialIterator_requirement_violation( i);

/ / Valid Expressions

//refinement

_STL_ERROR::

dereference_operator_and_assignment_requirement_violation( i);

}

};

 

/ * InputIterator Requirements */

 

//输入迭代器的refinement

template <class _InputIterator>

struct _InputIterator_concept_specification {

static void

_InputIterator_requirement_violation(_InputIterator

/ / Refinement of TrivialIterator

_TrivialIterator_concept_specification<_InputIterator>::

_TrivialIterator_requirement_violation( i);

/ / Associated Types

 

 

 

 

 

__i) {

 

difference_type_type_definition_requirement_violation<_InputIterator

 

 

 

difference_type_type_definition_requirement_violation<_InputIterator

>();

reference_type_definition_requirement_violation<_InputIterator>();

pointer_type_definition_requirement_violation<_InputIterator>();

iterator_category_type_definition_requirement_violation<

_InputIterator>();

/ / Valid Expressions

_STL_ERROR:: preincrement_operator_requirement_violation( i);

_STL_ERROR:: postincrement_operator_requirement_violation( i);

}

};

 

/ * OutputIterator Requirements */

 

//输出迭代器的refinement

template <class _OutputIterator>

struct _OutputIterator_concept_specification {

static void

_OutputIterator_requirement_violation(_OutputIterator

/ / Refinement of Assignable

_Assignable_concept_specification<_OutputIterator>::

_Assignable_requirement_violation( i);

/ / Associated Types

iterator_category_type_definition_requirement_violation<

_OutputIterator>();

/ / Valid Expressions

 

 

 

 

 

__i) {

 

_STL_ERROR:: dereference_operator_requirement_violation( i);

_STL_ERROR:: preincrement_operator_requirement_violation( i);

_STL_ERROR:: postincrement_operator_requirement_violation( i);

_STL_ERROR::

postincrement_operator_and_assignment_requirement_violation( i, *

i);

}

};

 

/ * ForwardIterator Requirements */

 

//单向迭代器的refinement

template <class _ForwardIterator>

struct _ForwardIterator_concept_specification {

static void

_ForwardIterator_requirement_violation(_ForwardIterator

/ / Refinement of InputIterator

_InputIterator_concept_specification<_ForwardIterator>::

_InputIterator_requirement_violation( i);

 

 

 

 

 

__i) {

 

}

};

//可修改单向迭代器的refinement

template <class _ForwardIterator>

struct _Mutable_ForwardIterator_concept_specification {

static void

_Mutable_ForwardIterator_requirement_violation(

_ForwardIterator i) {

_ForwardIterator_concept_specification<_ForwardIterator>::

_ForwardIterator_requirement_violation( i);

/ / Refinement of OutputIterator

_OutputIterator_concept_specification<_ForwardIterator>::

 

 

 

_OutputIterator_requirement_violation( i);

}

};

 

/ * BidirectionalIterator Requirements */

//双向迭代器refinement

template <class _BidirectionalIterator>

struct _BidirectionalIterator_concept_specification {

static void

_BidirectionalIterator_requirement_violation(

_BidirectionalIterator i) {

/ / Refinement of ForwardIterator

_ForwardIterator_concept_specification<_BidirectionalIterator>::

_ForwardIterator_requirement_violation( i);

/ / Valid Expressions

_STL_ERROR:: predecrement_operator_requirement_violation( i);

_STL_ERROR:: postdecrement_operator_requirement_violation( i);

}

};

//可修改的双向迭代器的refinement

template <class _BidirectionalIterator>

struct _Mutable_BidirectionalIterator_concept_specification {

static void

_Mutable_BidirectionalIterator_requirement_violation(

_BidirectionalIterator i)

{

_BidirectionalIterator_concept_specification<_BidirectionalIterator>::

_BidirectionalIterator_requirement_violation( i);

/ / Refinement of mutable_ForwardIterator

_Mutable_ForwardIterator_concept_specification<_BidirectionalIterator>

::

_Mutable_ForwardIterator_requirement_violation( i);

typedef typename

value_type_type_definition_requirement_violation<

_BidirectionalIterator>::value_type T;

typename _Mutable_trait< T>::_Type* tmp_ptr = 0;

/ / Valid Expressions

_STL_ERROR::

postincrement_operator_and_assignment_requirement_violation( i,

*

tmp_ptr);

}

} ? end _Mutable_BidirectionalIterator_concept_specification ? ;

 

/ * RandomAccessIterator Requirements */

//自由迭代器的refinement

template <class _RandAccIter>

struct _RandomAccessIterator_concept_specification {

static void

_RandomAccessIterator_requirement_violation(_RandAccIter

i) {

/ / Refinement of BidirectionalIterator

_BidirectionalIterator_concept_specification<_RandAccIter>::

_BidirectionalIterator_requirement_violation( i);

/ / Refinement of LessThanComparable

_LessThanComparable_concept_specification<_RandAccIter>::

 

 

 

_LessThanComparable_requirement_violation( i);

typedef typename

value_type_type_definition_requirement_violation<_RandAccIter>

::value_type

value_type;

typedef typename

difference_type_type_definition_requirement_violation<

_RandAccIter>

::difference_type

_Dist;

typedef typename _Mutable_trait<_Dist>::_Type _MutDist;

 

/ / Valid Expressions

_STL_ERROR:: iterator_addition_assignment_requirement_violation(__i,

 

_MutDist());

_STL_ERROR:: iterator_addition_requirement_violation(__i,

_MutDist());

_STL_ERROR::

iterator_subtraction_assignment_requirement_violation(__i,

_MutDist());

_STL_ERROR:: iterator_subtraction_requirement_violation(__i,

_MutDist());

_STL_ERROR:: difference_operator_requirement_violation(__i, __i,

_MutDist());

typename _Mutable_trait<value_type>::_Type* dummy_ptr = 0;

_STL_ERROR:: element_access_operator_requirement_violation(__i,

 

 

dummy_ptr,

 

);

} ? end _RandomAccessIterator_requirement_violation ?

} ? end _RandomAccessIterator_concept_specification ? ;

 

 

 

_MutDist()

 

//双向自由迭代器的refinement

 

template <class _RandAccIter>

 

struct

_Mutable_RandomAccessIterator_concept_specification {

static void

_Mutable_RandomAccessIterator_requirement_violation(

_RandAccIter i)

{

_RandomAccessIterator_concept_specification<_RandAccIter>::

_RandomAccessIterator_requirement_violation( i);

/ / Refinement of mutable_BidirectionalIterator

_Mutable_BidirectionalIterator_concept_specification<_RandAccIter>::

_Mutable_BidirectionalIterator_requirement_violation( i);

typedef typename

value_type_type_definition_requirement_violation<_RandAccIter>

::value_type

value_type;

typedef typename

difference_type_type_definition_requirement_violation<

_RandAccIter>

::difference_type

_Dist;

 

 

 

typename _Mutable_trait<value_type>::_Type* tmp_ptr = 0;

/ / Valid Expressions

_STL_ERROR:: element_assignment_operator_requirement_violation(__i,

tmp_ptr, _Dist());

} ? end _Mutable_RandomAccessIterator_requirement_violation ?

} ? end _Mutable_RandomAccessIterator_concept_specification ? ;

 

#define STL_TYPEDEF_REQUIREMENT( REQUIREMENT) \

template <class Type> \

struct ## REQUIREMENT## typedef_requirement_violation { \

typedef typename Type:: REQUIREMENT REQUIREMENT; \

}

//生成能查看内部类型定义的结构体,此处只是为了方便而使用了宏定义

 

__STL_TYPEDEF_REQUIREMENT(value_type);

__STL_TYPEDEF_REQUIREMENT(difference_type);

__STL_TYPEDEF_REQUIREMENT(size_type);

__STL_TYPEDEF_REQUIREMENT(reference);

__STL_TYPEDEF_REQUIREMENT(const_reference);

__STL_TYPEDEF_REQUIREMENT(pointer);

__STL_TYPEDEF_REQUIREMENT(const_pointer);

 

 

//空间配置器的specification

template <class _Alloc>

struct _Allocator_concept_specification {

static void

 

_Allocator_requirement_violation(_Alloc

/ / Refinement of DefaultConstructible

 

__a) {

 

_DefaultConstructible_concept_specification<_Alloc>::

_DefaultConstructible_requirement_violation( a);

/ / Refinement of EqualityComparable

_EqualityComparable_concept_specification<_Alloc>::

_EqualityComparable_requirement_violation( a);

/ / Associated Types

value_type typedef_requirement_violation<_Alloc>();

difference_type typedef_requirement_violation<_Alloc>();

size_type typedef_requirement_violation<_Alloc>();

reference typedef_requirement_violation<_Alloc>();

const_reference typedef_requirement_violation<_Alloc>();

pointer typedef_requirement_violation<_Alloc>();

const_pointer typedef_requirement_violation<_Alloc>();

typedef typename _Alloc::value_type _Tp;

 

/ /     STL_REQUIRES_SAME_TYPE(typename _Alloc::     STL_TEMPLATE rebind<_Tp>::

other,

/ /    _Alloc);

} ? end _Allocator_requirement_violation ?

} ? end _Allocator_concept_specification ? ;

 

#endif / *     STL_USE_CONCEPT_CHECKS */

 

#endif / *     CONCEPT_CHECKS_H */

 

/ / Local Variables:

/ / mode:C++

 

 

 

II End:

  评论这张
 
阅读(1040)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017