1 2 3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 4 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 5<html xmlns="http://www.w3.org/1999/xhtml"> 6 <head> 7 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 8 9 <title>Concepts - Boost.GIL documentation</title> 10 <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> 11 <link rel="stylesheet" href="../_static/style.css" type="text/css" /> 12 <script type="text/javascript"> 13 var DOCUMENTATION_OPTIONS = { 14 URL_ROOT: '../', 15 VERSION: '', 16 COLLAPSE_MODINDEX: false, 17 FILE_SUFFIX: '.html' 18 }; 19 </script> 20 <script type="text/javascript" src="../_static/jquery.js"></script> 21 <script type="text/javascript" src="../_static/underscore.js"></script> 22 <script type="text/javascript" src="../_static/doctools.js"></script> 23 <link rel="index" title="Index" href="../genindex.html" /> 24 <link rel="search" title="Search" href="../search.html" /> 25 <link rel="top" title="Boost.GIL documentation" href="../index.html" /> 26 <link rel="up" title="Design Guide" href="index.html" /> 27 <link rel="next" title="Point" href="point.html" /> 28 <link rel="prev" title="Basics" href="basics.html" /> 29 </head> 30 <body> 31 <div class="header"> 32 <table border="0" cellpadding="7" cellspacing="0" width="100%" summary= 33 "header"> 34 <tr> 35 <td valign="top" width="300"> 36 <h3><a href="../index.html"><img 37 alt="C++ Boost" src="../_static/gil.png" border="0"></a></h3> 38 </td> 39 40 <td > 41 <h1 align="center"><a href="../index.html"></a></h1> 42 </td> 43 <td> 44 <div id="searchbox" style="display: none"> 45 <form class="search" action="../search.html" method="get"> 46 <input type="text" name="q" size="18" /> 47 <input type="submit" value="Search" /> 48 <input type="hidden" name="check_keywords" value="yes" /> 49 <input type="hidden" name="area" value="default" /> 50 </form> 51 </div> 52 <script type="text/javascript">$('#searchbox').show(0);</script> 53 </td> 54 </tr> 55 </table> 56 </div> 57 <hr/> 58 <div class="content"> 59 <div class="navbar" style="text-align:right;"> 60 61 62 <a class="prev" title="Basics" href="basics.html"><img src="../_static/prev.png" alt="prev"/></a> 63 <a class="up" title="Design Guide" href="index.html"><img src="../_static/up.png" alt="up"/></a> 64 <a class="next" title="Point" href="point.html"><img src="../_static/next.png" alt="next"/></a> 65 66 </div> 67 68 <div class="section" id="concepts"> 69<h1>Concepts</h1> 70<p>All constructs in GIL are models of GIL concepts. A <em>concept</em> is a set of 71requirements that a type (or a set of related types) must fulfill to be used 72correctly in generic algorithms. The requirements include syntactic and 73algorithmic guarantees. For example, GIL class <code class="docutils literal"><span class="pre">pixel</span></code> is a model of GIL 74<code class="docutils literal"><span class="pre">PixelConcept</span></code>. The user may substitute the pixel class with one of their 75own, and, as long as it satisfies the requirements of <code class="docutils literal"><span class="pre">PixelConcept</span></code>, 76all other GIL classes and algorithms can be used with it. 77See more about concepts is avaialble at 78<a class="reference external" href="https://web.archive.org/web/20160324115943/http://www.generic-programming.org/languages/conceptcpp/">Generic Programming in ConceptC++</a></p> 79<p>In this document we will use a syntax for defining concepts that is described 80in the C++ standard proposal paper 81<a class="reference external" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2081.pdf">[N2081] Concepts</a>.</p> 82<p>Here are some common concepts that will be used in GIL. 83Most of them are defined at the 84<a class="reference external" href="https://web.archive.org/web/20160326060858/http://www.generic-programming.org/languages/conceptcpp/concept_web.php">ConceptC++ Concept Web</a>:</p> 85<div class="highlight-cpp"><div class="highlight"><pre><span class="k">auto</span> <span class="n">concept</span> <span class="n">DefaultConstructible</span><span class="o"><</span><span class="k">typename</span> <span class="n">T</span><span class="o">></span> 86<span class="p">{</span> 87 <span class="n">T</span><span class="o">::</span><span class="n">T</span><span class="p">();</span> 88<span class="p">};</span> 89 90<span class="k">auto</span> <span class="n">concept</span> <span class="n">CopyConstructible</span><span class="o"><</span><span class="k">typename</span> <span class="n">T</span><span class="o">></span> 91<span class="p">{</span> 92 <span class="n">T</span><span class="o">::</span><span class="n">T</span><span class="p">(</span><span class="n">T</span><span class="p">);</span> 93 <span class="n">T</span><span class="o">::~</span><span class="n">T</span><span class="p">();</span> 94<span class="p">};</span> 95 96<span class="k">auto</span> <span class="n">concept</span> <span class="n">Assignable</span><span class="o"><</span><span class="k">typename</span> <span class="n">T</span><span class="p">,</span> <span class="k">typename</span> <span class="n">U</span> <span class="o">=</span> <span class="n">T</span><span class="o">></span> 97<span class="p">{</span> 98 <span class="k">typename</span> <span class="n">result_type</span><span class="p">;</span> 99 <span class="n">result_type</span> <span class="k">operator</span><span class="o">=</span><span class="p">(</span><span class="n">T</span><span class="o">&</span><span class="p">,</span> <span class="n">U</span><span class="p">);</span> 100<span class="p">};</span> 101 102<span class="k">auto</span> <span class="n">concept</span> <span class="n">EqualityComparable</span><span class="o"><</span><span class="k">typename</span> <span class="n">T</span><span class="p">,</span> <span class="k">typename</span> <span class="n">U</span> <span class="o">=</span> <span class="n">T</span><span class="o">></span> 103<span class="p">{</span> 104 <span class="kt">bool</span> <span class="k">operator</span><span class="o">==</span><span class="p">(</span><span class="n">T</span> <span class="n">x</span><span class="p">,</span> <span class="n">U</span> <span class="n">y</span><span class="p">);</span> 105 <span class="kt">bool</span> <span class="k">operator</span><span class="o">!=</span><span class="p">(</span><span class="n">T</span> <span class="n">x</span><span class="p">,</span> <span class="n">U</span> <span class="n">y</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="o">!</span><span class="p">(</span><span class="n">x</span><span class="o">==</span><span class="n">y</span><span class="p">);</span> <span class="p">}</span> 106<span class="p">};</span> 107 108<span class="n">concept</span> <span class="n">SameType</span><span class="o"><</span><span class="k">typename</span> <span class="n">T</span><span class="p">,</span> <span class="k">typename</span> <span class="n">U</span><span class="o">></span> <span class="p">{</span> <span class="cm">/* unspecified */</span> <span class="p">};</span> 109<span class="k">template</span><span class="o"><</span><span class="k">typename</span> <span class="n">T</span><span class="o">></span> <span class="n">concept_map</span> <span class="n">SameType</span><span class="o"><</span><span class="n">T</span><span class="p">,</span> <span class="n">T</span><span class="o">></span> <span class="p">{</span> <span class="cm">/* unspecified */</span> <span class="p">};</span> 110 111<span class="k">auto</span> <span class="n">concept</span> <span class="n">Swappable</span><span class="o"><</span><span class="k">typename</span> <span class="n">T</span><span class="o">></span> 112<span class="p">{</span> 113 <span class="kt">void</span> <span class="n">swap</span><span class="p">(</span><span class="n">T</span><span class="o">&</span> <span class="n">t</span><span class="p">,</span> <span class="n">T</span><span class="o">&</span> <span class="n">u</span><span class="p">);</span> 114<span class="p">};</span> 115</pre></div> 116</div> 117<p>Here are some additional basic concepts that GIL needs:</p> 118<div class="highlight-cpp"><div class="highlight"><pre><span class="k">auto</span> <span class="n">concept</span> <span class="n">Regular</span><span class="o"><</span><span class="k">typename</span> <span class="n">T</span><span class="o">></span> <span class="o">:</span> 119 <span class="n">DefaultConstructible</span><span class="o"><</span><span class="n">T</span><span class="o">></span><span class="p">,</span> 120 <span class="n">CopyConstructible</span><span class="o"><</span><span class="n">T</span><span class="o">></span><span class="p">,</span> 121 <span class="n">EqualityComparable</span><span class="o"><</span><span class="n">T</span><span class="o">></span><span class="p">,</span> 122 <span class="n">Assignable</span><span class="o"><</span><span class="n">T</span><span class="o">></span><span class="p">,</span> 123 <span class="n">Swappable</span><span class="o"><</span><span class="n">T</span><span class="o">></span> 124<span class="p">{};</span> 125 126<span class="k">auto</span> <span class="n">concept</span> <span class="n">Metafunction</span><span class="o"><</span><span class="k">typename</span> <span class="n">T</span><span class="o">></span> 127<span class="p">{</span> 128 <span class="k">typename</span> <span class="n">type</span><span class="p">;</span> 129<span class="p">};</span> 130</pre></div> 131</div> 132</div> 133 134 135 <div class="navbar" style="text-align:right;"> 136 137 138 <a class="prev" title="Basics" href="basics.html"><img src="../_static/prev.png" alt="prev"/></a> 139 <a class="up" title="Design Guide" href="index.html"><img src="../_static/up.png" alt="up"/></a> 140 <a class="next" title="Point" href="point.html"><img src="../_static/next.png" alt="next"/></a> 141 142 </div> 143 </div> 144 <div class="footer" role="contentinfo"> 145 Last updated on 2020-08-11 15:08:48. 146 Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.6. 147 </div> 148 </body> 149</html>