1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title> Concepts and External Concepts </title><meta http-equiv="Content-Type"content="text/html; charset=iso-8859-1"></head> <body><table ><tr ><td ><img src="../../../../boost.png" width="100%" border="0"></td><td ><h1 >Concepts and External Concepts</h1></td></tr></table><p >Generic programming in C++ is characterized by the use of function and class templates where 2 the template parameter(s) must satisfy certain requirements.Often these 3 requirements are so important that we give them a name: we call 4 such a set of type requirements a <b>concept</b>. We say that a type <i> 5 conforms to a concept</i> or that it <i>is a model of a concept</i> if it 6 satisfies all of those requirements. The concept can be specified as a set 7 of member functions with well-defined semantics 8 and a set of nested typedefs with well-defined properties.</p><p >Often it much more flexible to provide free-standing functions and typedefs 9 which provides the exact same semantics (but a different syntax) as 10 specified 11 by the concept. This allows generic code to treat different types <i> as if 12 </i> they fulfilled the concept. In this case we say that the concept has 13 been <b> externalized </b> or that the new requirements constitutes an <b>external 14 concept </b>. We say that a type <i> conforms to an external concept </i> 15 or that it <i> is a model of an external concept </i>. A concept may exist 16 without a corresponding external concept and conversely.</p><p >Whenever a concept specifies a member function, the corresponding external 17 concept 18 must specify a free-standing function of the same name, same return type and 19 the same argument list except there is an extra first argument which must 20 be of the type (or a reference to that type) that is to fulfill the external 21 concept. If the corresonding member function has any cv-qulifiers, the 22 first argument must have the same cv-qualifiers. Whenever a concept 23 specifies a nested typedef, the corresponding external concept 24 specifies a <b>type-generator</b>, that is, a type with a nested typedef 25 named <code>type</code>. The type-generator has the name as the nested typedef with 26 <code>_of</code> appended. 27 The converse relationship of an external concept and its corresponding concept 28 also holds.</p><p ><b ><i >Example:</i></b></p><p >A type <code>T</code> fulfills the FooConcept if it 29 has the follwing public members:</p><code> void T::foo( int ) const; <br> 30 int T::bar(); <br> 31 typedef <i>implementation defined </i> foo_type;</code><p >The corresponding external concept is the ExternalFooConcept.</p><p >A type <code>T</code> fullfills the ExternalFooConcept if these 32 free-standing functions and type-generators exists:</p><code>void foo( const T&, int ); <br> 33 int bar( T& ); <br> 34 foo_type_of< T >::type;</code> <br> <br><hr size="1" ><h3 >Literature</h3><ul ><li > <a href="http://www.boost.org/more/generic_programming.html#type_generator" target="_self" >Type Generators</a> </li><li > <a href="http://www.boost.org/more/generic_programming.html#concept" target="_self" >Concepts</a> </li><li > <a href="https://www.boost.org/sgi/stl/stl_introduction.html" target="_self" >Concepts and SGI STL</a> </li></ul><hr size="1" ><p >© Thorsten Ottosen 2003-2004 (nesotto_AT_cs.auc.dk). 35<br>Use, modification and distribution is subject to the Boost 36 Software License, Version 1.0. (See accompanying file 37 <code class="filename">LICENSE_1_0.txt</code> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 38</br> 39</p> 40 <!-- Copyright Dezide Aps 2003-2004 --> 41