#define _STLP_REQUIRES(__type_var, __concept) \do { \ void (*__x)( __type_var ) = __concept##_concept_specification< __type_var >\ ::##__concept##_requirement_violation; __x = __x; } while (0)
Which, for (VAR,CONCEPT) gives
do { void (*__x)( VAR ) = CONCEPT_concept_specification<VAR>::CONCEPT_requirement_violation; __x = __x; } while (0)
Where CONCEPT_requirement_specification is a template class containing one function, CONCEPT_requirement_violation. That function (directly or indirectly by instanciating other function templates) contains code executing the operations that the concept is supposed to implement.
e.g. at the end of the instanciation chain ''Default Constructible'' is checked by
template <class _Type> static _Type __default_constructor_requirement_violation(_Type) { return _Type(); }
which, if executed, would default-construct its templated type.
This relies on the fact that templates that are not used are not instanciated. The assignment of the function pointer __x to itself , while a no-op, is sufficient to cause the instanciation of the template. Which will fail to compile if the template parameter does not implement the required operations.
Normally, the compiler will recognize that the function pointer is never really used during its lifetime and will optimize it away. If not, you have a performance cost equivalent to the initialisation of a single local parameter and its self assignment : one MOV to set it to a constant (the address) and one intra-register to itself (though _that_ should be optimized). The functions actually referenced are never executed !
STLPort use a macro to enables or disable concept checks (_STLP_USE_CONCEPT_CHECKS) depending on the compiler.
I think that sums it all. Pretty nifty IMHO.
Boost also has a concept-check module to that effect.
Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]