From: zhongling on
I want to modify STL to suite my requirement, So I download sgi STL ,
Now I am reading one file of them "concept_checks.h", I don't how it
can check the concept and report error when compile,
such as follow semantics,I need some anotate.

#define __STL_REQUIRES(__type_var, __concept) \
do { \
void (*__x)( __type_var ) = __concept##_concept_specification<
__type_var >\
::__concept##_requirement_violation; __x = __x; } while (0)


#define __STL_GENERATOR_CHECK(__func, __ret) \
do { \
__ret (*__x)( __func&) = \
_STL_GENERATOR_ERROR< \
__func, __ret>::__generator_requirement_violation; \
__x = __x; } while (0)


#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



I need some help to anotate these sentence, complete file is follow ,it
can be referenced.




/*
* 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)


#def
From: Francis Glassborow on
In article <1156649953.743644.327220(a)i42g2000cwa.googlegroups.com>,
zhongling(a)webmail.hzau.edu.cn writes
>I want to modify STL to suite my requirement, So I download sgi STL ,
>Now I am reading one file of them "concept_checks.h", I don't how it
>can check the concept and report error when compile,
>such as follow semantics,I need some anotate.

Concepts and concept checking is something that is being worked on for
the next version of the C++ Standard due in 2009. I suspect (but am not
certain) that you have picked up a file that is part of the experimental
work going on to gain experience of these before finally including them
into the C++ Standard.

In addition you should check whether you have permission to alter the
source code you have downloaded (just because the code is made available
does not automatically grant permission for modification). Were I
looking for standard library source to modify I would look for the gcc
(g++) implementation.


--
Francis Glassborow ACCU
Author of 'You Can Do It!' and "You Can Program in C++"
see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
From: Bob on
On Sun, 27 Aug 2006 10:49:48 +0100, Francis Glassborow
<francis(a)robinton.demon.co.uk> wrote:

>In article <1156649953.743644.327220(a)i42g2000cwa.googlegroups.com>,
>zhongling(a)webmail.hzau.edu.cn writes
>>I want to modify STL to suite my requirement, So I download sgi STL ,
>>Now I am reading one file of them "concept_checks.h", I don't how it
>>can check the concept and report error when compile,
>>such as follow semantics,I need some anotate.
>
>Concepts and concept checking is something that is being worked on for
>the next version of the C++ Standard due in 2009. I suspect (but am not
>certain) that you have picked up a file that is part of the experimental
>work going on to gain experience of these before finally including them
>into the C++ Standard.
>
>In addition you should check whether you have permission to alter the
>source code you have downloaded (just because the code is made available
>does not automatically grant permission for modification). Were I
>looking for standard library source to modify I would look for the gcc
>(g++) implementation.

Briefly looking over the included code, it appears that most of this
comes out of Matt Austern's book. Matt divided his book into a
concepts section and then a model of concept section. I believe that
he worked for SGI when he wrote the book.

http://www.awprofessional.com/bookstore/product.asp?isbn=0201309564&redir=1&rl=1

There is also restricted permission to use the code.

"/*
* 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.
*/"

Best wishes,

Bob
 | 
Pages: 1
Prev: a switch statement
Next: missing file?