<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Three Kinds of&#160;Concepts</title>
	<atom:link href="http://cpp-next.com/archive/2009/08/three-kinds-of-concepts/feed/" rel="self" type="application/rss+xml" />
	<link>http://cpp-next.com/archive/2009/08/three-kinds-of-concepts/</link>
	<description>The next generation of C++</description>
	<lastBuildDate>Wed, 08 Sep 2010 20:02:40 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Alex Karpenko</title>
		<link>http://cpp-next.com/archive/2009/08/three-kinds-of-concepts/comment-page-1/#comment-238</link>
		<dc:creator>Alex Karpenko</dc:creator>
		<pubDate>Fri, 16 Oct 2009 03:04:56 +0000</pubDate>
		<guid isPermaLink="false">http://cpp-next.com/?p=253#comment-238</guid>
		<description>&lt;p&gt;Hi Guys,&lt;/p&gt;

&lt;p&gt;Let me preface this comment by saying that I&#039;ve read all posts with great interest. This is an excellent blog. I&#039;ve learned a great deal from the posts and comments. I&#039;m very excited about C++0x. Type inference, range-based for loops, closures, and initializer lists can&#039;t come soon enough!&lt;/p&gt;

&lt;p&gt;I do have a couple of gripes though that I wanted to rant about. My biggest issue is probably the alternate function syntax. The justification for it seems to be as follows:&lt;/p&gt;

&lt;pre&gt;template&lt;typename LHS, typename RHS&gt; 
  decltype&#040;lhs+rhs&#041; AddingFunc&#040;const LHS &amp;lhs, const RHS &amp;rhs&#041; &#123;return lhs + rhs;&#125;&lt;/pre&gt;

&lt;p&gt;This is apparently not legal since lhs and rhs have not yet been defined; so the proposed solution is:&lt;/p&gt;

&lt;pre&gt;template&lt;typename LHS, typename RHS&gt; 
  &#091;&#093; AddingFunc&#040;const LHS &amp;lhs, const RHS &amp;rhs&#041; -&gt; decltype&#040;lhs+rhs&#041; &#123;return lhs + rhs;&#125;&lt;/pre&gt;

&lt;p&gt;When I first read this, I was baffled. Really? Why not just go with the former (saner) syntax and require the compiler to &quot;look ahead&quot; in the function declaration? It&#039;s all one statement anyway! Just look at the function parameters first, then look at the return type. Who cares that it&#039;s typed in the reverse order?!&lt;/p&gt;

&lt;p&gt;This seems akin to the vector&lt;list&lt;int&gt;&gt; issue, which was resolved by having the compiler do &quot;the right thing&quot;(tm) instead of needlessly burdening the programmer. In fact, this is even less of an issue in the code above, since there is no ambiguity. The former statement is sane, while the latter is verbose and adds unneeded complexity to an already complex language. Just great. We take a step forward with uniform initialization, and take one step back with a new way to declare functions. Lovely. Here&#039;s a crazy idea: why not force the few compiler folks to do a little bit of extra work &quot;looking ahead&quot;, instead of forcing the rest of us to suffer the new verbose function syntax until it&#039;s inevitably &quot;fixed&quot; 7 years down the road; much like the vector&lt;list&lt;int&gt;&gt; non-issue.&lt;/p&gt;

&lt;p&gt;My rant got a bit out of hand length-wise, so I&#039;m going to submit the second part on concepts separately. In the meantime I&#039;d love to hear what other folks think of the new function syntax.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi Guys,</p>

<p>Let me preface this comment by saying that I&#8217;ve read all posts with great interest. This is an excellent blog. I&#8217;ve learned a great deal from the posts and comments. I&#8217;m very excited about C++0x. Type inference, range-based for loops, closures, and initializer lists can&#8217;t come soon enough!</p>

<p>I do have a couple of gripes though that I wanted to rant about. My biggest issue is probably the alternate function syntax. The justification for it seems to be as follows:</p>

<pre>template&lt;typename LHS, typename RHS&gt; 
  decltype&#40;lhs+rhs&#41; AddingFunc&#40;const LHS &amp;lhs, const RHS &amp;rhs&#41; &#123;return lhs + rhs;&#125;</pre>

<p>This is apparently not legal since lhs and rhs have not yet been defined; so the proposed solution is:</p>

<pre>template&lt;typename LHS, typename RHS&gt; 
  &#91;&#93; AddingFunc&#40;const LHS &amp;lhs, const RHS &amp;rhs&#41; -&gt; decltype&#40;lhs+rhs&#41; &#123;return lhs + rhs;&#125;</pre>

<p>When I first read this, I was baffled. Really? Why not just go with the former (saner) syntax and require the compiler to &#8220;look ahead&#8221; in the function declaration? It&#8217;s all one statement anyway! Just look at the function parameters first, then look at the return type. Who cares that it&#8217;s typed in the reverse order?!</p>

<p>This seems akin to the vector&lt;list&lt;int&gt;&gt; issue, which was resolved by having the compiler do &#8220;the right thing&#8221;(tm) instead of needlessly burdening the programmer. In fact, this is even less of an issue in the code above, since there is no ambiguity. The former statement is sane, while the latter is verbose and adds unneeded complexity to an already complex language. Just great. We take a step forward with uniform initialization, and take one step back with a new way to declare functions. Lovely. Here&#8217;s a crazy idea: why not force the few compiler folks to do a little bit of extra work &#8220;looking ahead&#8221;, instead of forcing the rest of us to suffer the new verbose function syntax until it&#8217;s inevitably &#8220;fixed&#8221; 7 years down the road; much like the vector&lt;list&lt;int&gt;&gt; non-issue.</p>

<p>My rant got a bit out of hand length-wise, so I&#8217;m going to submit the second part on concepts separately. In the meantime I&#8217;d love to hear what other folks think of the new function syntax.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: kempozone</title>
		<link>http://cpp-next.com/archive/2009/08/three-kinds-of-concepts/comment-page-1/#comment-215</link>
		<dc:creator>kempozone</dc:creator>
		<pubDate>Sun, 11 Oct 2009 18:30:08 +0000</pubDate>
		<guid isPermaLink="false">http://cpp-next.com/?p=253#comment-215</guid>
		<description>&lt;p&gt;I&lt;a HREF=&quot;http://fedora-commons.org/confluence/display/~billtinsley1971&quot; rel=&quot;nofollow&quot;&gt;&#039;&lt;/A&gt;m sure many of you are like me and one of the first things you do in the morning is head here and check out the new post.  Along with seeing the new posts, I&#039;m also always checking out the blog roll rss feed and watching them grow, or shrink sometimes.  In one of my past ...but all in all excellent site.   Keep it up!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I<a HREF="http://fedora-commons.org/confluence/display/~billtinsley1971" rel="nofollow">&#8216;</a>m sure many of you are like me and one of the first things you do in the morning is head here and check out the new post.  Along with seeing the new posts, I&#8217;m also always checking out the blog roll rss feed and watching them grow, or shrink sometimes.  In one of my past &#8230;but all in all excellent site.   Keep it up!</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Terje Slettebø</title>
		<link>http://cpp-next.com/archive/2009/08/three-kinds-of-concepts/comment-page-1/#comment-125</link>
		<dc:creator>Terje Slettebø</dc:creator>
		<pubDate>Mon, 07 Sep 2009 16:58:49 +0000</pubDate>
		<guid isPermaLink="false">http://cpp-next.com/?p=253#comment-125</guid>
		<description>&lt;blockquote cite=&quot;comment-119&quot;&gt;
&lt;strong&gt;&lt;a href=&quot;#comment-119&quot; rel=&quot;nofollow&quot;&gt;Ken Camann&lt;/a&gt;&lt;/strong&gt;:Calling normalize 
changes &quot;*this&quot; but you do not want it to change &quot;this&quot; or return a new 
object. Instead, you want to say that x has the same type and does move in 
memory at all, but at compile time conforms to a different semantic concept, 
that of being a normal vector.&lt;/blockquote&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;The problem with this approach is that the compiler can&#039;t in general know 
whether the object has gone through the change or not (because it happens at 
run-time):&lt;/p&gt;

&lt;pre&gt;if&#040;some_user_input&#040;&#041;&#041;
  x.normalize&#040;&#041;;
&#160;
ThisOnlyTakesNormalVectors&#040;x&#041;; // Call succeeds?&lt;/pre&gt;

&lt;p&gt;However, using move semantics and clever compiler optimisations (such as 
RVO), you might get away with code like below, with little or no overhead 
(and no movement of data):&lt;/p&gt;

&lt;pre&gt;Vector3Impl x&#040;1, 2, 3&#041;;
&#160;
Vector3Normalized y=x.normalize&#040;&#041;;
&#160;
ThisOnlyTakesNormalVectors&#040;y&#041;; // Ok&lt;/pre&gt;
</description>
		<content:encoded><![CDATA[<blockquote cite="comment-119">
<strong><a href="#comment-119" rel="nofollow">Ken Camann</a></strong>:Calling normalize 
changes &#8220;*this&#8221; but you do not want it to change &#8220;this&#8221; or return a new 
object. Instead, you want to say that x has the same type and does move in 
memory at all, but at compile time conforms to a different semantic concept, 
that of being a normal vector.</blockquote>

<p></p>

<p>The problem with this approach is that the compiler can&#8217;t in general know 
whether the object has gone through the change or not (because it happens at 
run-time):</p>

<pre>if&#40;some_user_input&#40;&#41;&#41;
  x.normalize&#40;&#41;;
&nbsp;
ThisOnlyTakesNormalVectors&#40;x&#41;; // Call succeeds?</pre>

<p>However, using move semantics and clever compiler optimisations (such as 
RVO), you might get away with code like below, with little or no overhead 
(and no movement of data):</p>

<pre>Vector3Impl x&#40;1, 2, 3&#41;;
&nbsp;
Vector3Normalized y=x.normalize&#40;&#41;;
&nbsp;
ThisOnlyTakesNormalVectors&#40;y&#41;; // Ok</pre>]]></content:encoded>
	</item>
	<item>
		<title>By: Sebastian</title>
		<link>http://cpp-next.com/archive/2009/08/three-kinds-of-concepts/comment-page-1/#comment-124</link>
		<dc:creator>Sebastian</dc:creator>
		<pubDate>Mon, 07 Sep 2009 09:28:51 +0000</pubDate>
		<guid isPermaLink="false">http://cpp-next.com/?p=253#comment-124</guid>
		<description>&lt;p&gt;Concepts is about types and not about states. Overload resolution is done at compile-time without checking some object&#039;s state. Dynamic dispatching (virtual functions) is also restricted to types and not states. If you want dynamic dispatching according to an object&#039;s state someone (you or the compiler directly supporting this language feature) needs to inspect the state (like a boolean flag is_normalized for example) and decide what to do next.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Concepts is about types and not about states. Overload resolution is done at compile-time without checking some object&#8217;s state. Dynamic dispatching (virtual functions) is also restricted to types and not states. If you want dynamic dispatching according to an object&#8217;s state someone (you or the compiler directly supporting this language feature) needs to inspect the state (like a boolean flag is_normalized for example) and decide what to do next.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Abrahams</title>
		<link>http://cpp-next.com/archive/2009/08/three-kinds-of-concepts/comment-page-1/#comment-121</link>
		<dc:creator>Dave Abrahams</dc:creator>
		<pubDate>Sun, 06 Sep 2009 17:46:32 +0000</pubDate>
		<guid isPermaLink="false">http://cpp-next.com/?p=253#comment-121</guid>
		<description>&lt;p&gt;http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2122.htm has as good an explanation as any other.  Note: even though my name is attached to that proposal I didn&#039;t really have anything to do with it.  Maybe if I had been more involved, it would have gotten more traction (or maybe not), but as it stood I never had time to work on it.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2122.htm" rel="nofollow">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2122.htm</a> has as good an explanation as any other.  Note: even though my name is attached to that proposal I didn&#8217;t really have anything to do with it.  Maybe if I had been more involved, it would have gotten more traction (or maybe not), but as it stood I never had time to work on it.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Ken Camann</title>
		<link>http://cpp-next.com/archive/2009/08/three-kinds-of-concepts/comment-page-1/#comment-119</link>
		<dc:creator>Ken Camann</dc:creator>
		<pubDate>Sat, 05 Sep 2009 23:43:48 +0000</pubDate>
		<guid isPermaLink="false">http://cpp-next.com/?p=253#comment-119</guid>
		<description>&lt;p&gt;I have an idea for something that would be interesting to see in concepts, but I am not sure how feasible it would be.  I&#039;m not sure if there is some hack using the old proposals that could make this work, but I am guessing the answer is no.&lt;/p&gt;

&lt;p&gt;Suppose you have a class that satisfies the &quot;Vector3&quot; concept, which is a 3 dimensional vector.  However, there is another concept called &quot;NormalVector3&quot; which has the expected length == 1 axiom and it doesn&#039;t let you use +=, -=, etc. to vector addition/subtraction or any other operation that might ruin the &quot;normalness&quot; of the vector.&lt;/p&gt;

&lt;p&gt;Now suppose you create an instance &quot;x&quot; of the &quot;Vector3Impl&quot; implementation class.  &quot;Vector3Impl&quot; satisfies the Vector3 concept.  Here is a declaration:&lt;/p&gt;

&lt;p&gt;Vector3Impl x(1, 2, 3); // Not a normal vector in general, but it could be!&lt;/p&gt;

&lt;p&gt;The thing is, once you call:&lt;/p&gt;

&lt;p&gt;x.normalize();&lt;/p&gt;

&lt;p&gt;the instance is now guaranteed to be a normal vector, except the method has no way of communicating this to the compiler without creating a new object of a different type that has different semantics.  Since the compiler doesn&#039;t know this, if you had a concept-overload like this:&lt;/p&gt;

&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;cpp&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;template&lt;/span&gt; &lt;span style=&quot;color: #000080;&quot;&gt;&lt;&lt;/span&gt;NormalVector3 N&lt;span style=&quot;color: #000080;&quot;&gt;&gt;&lt;/span&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; ThisOnlyTakesNormalVectors &lt;span style=&quot;color: #008000;&quot;&gt;&#040;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; N&lt;span style=&quot;color: #000040;&quot;&gt;&amp;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&#041;&lt;/span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;as far as I understand, you cannot pass x to it because x has the original type Vector3Impl, which satisfies the concept Vector3 and not NormalVector3.  By the way, perhaps that is what the other poster meant when they referred to &quot;concept_cast&quot;?&lt;/p&gt;

&lt;p&gt;Calling normalize changes &quot;*this&quot; but you do not want it to change &quot;this&quot; or return a new object.  Instead, you want to say that x has the same type and does move in memory at all, but at compile time conforms to a different semantic concept, that of being a normal vector.&lt;/p&gt;

&lt;p&gt;I wouldn&#039;t use vectors and matrices just for exposition; they occur &lt;em&gt;everywhere&lt;/em&gt; in scientific computing, where performance is critical and you can&#039;t copy anything.  It would be nice to be able to say &quot;once I modify this l-value, I can now guarantee (or drop a guarantee) that an object belongs to certain overload set, which will change how it is treated by the compiler after the modification point&quot;.&lt;/p&gt;

&lt;p&gt;For example, you tack some syntactic information onto the Vector3Impl::normalize method, so that upon returning it mutates (in some sense) the concept overload resolution of x, so that it can now be passed into the function &quot;ThisOnlyTakesNormalVectors&quot;.&lt;/p&gt;

&lt;p&gt;I don&#039;t know what to call this, or if its a very bad idea in the general case.  It is like &quot;instance concepts&quot; instead of &quot;type concepts&quot;.  It&#039;s different than dynamic typing because the methods explain at compile time how they are changing the concept of the mutated object.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I have an idea for something that would be interesting to see in concepts, but I am not sure how feasible it would be.  I&#8217;m not sure if there is some hack using the old proposals that could make this work, but I am guessing the answer is no.</p>

<p>Suppose you have a class that satisfies the &#8220;Vector3&#8243; concept, which is a 3 dimensional vector.  However, there is another concept called &#8220;NormalVector3&#8243; which has the expected length == 1 axiom and it doesn&#8217;t let you use +=, -=, etc. to vector addition/subtraction or any other operation that might ruin the &#8220;normalness&#8221; of the vector.</p>

<p>Now suppose you create an instance &#8220;x&#8221; of the &#8220;Vector3Impl&#8221; implementation class.  &#8220;Vector3Impl&#8221; satisfies the Vector3 concept.  Here is a declaration:</p>

<p>Vector3Impl x(1, 2, 3); // Not a normal vector in general, but it could be!</p>

<p>The thing is, once you call:</p>

<p>x.normalize();</p>

<p>the instance is now guaranteed to be a normal vector, except the method has no way of communicating this to the compiler without creating a new object of a different type that has different semantics.  Since the compiler doesn&#8217;t know this, if you had a concept-overload like this:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">template</span> <span style="color: #000080;">&lt;</span>NormalVector3 N<span style="color: #000080;">&gt;</span>
<span style="color: #0000ff;">void</span> ThisOnlyTakesNormalVectors <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> N<span style="color: #000040;">&amp;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>as far as I understand, you cannot pass x to it because x has the original type Vector3Impl, which satisfies the concept Vector3 and not NormalVector3.  By the way, perhaps that is what the other poster meant when they referred to &#8220;concept_cast&#8221;?</p>

<p>Calling normalize changes &#8220;*this&#8221; but you do not want it to change &#8220;this&#8221; or return a new object.  Instead, you want to say that x has the same type and does move in memory at all, but at compile time conforms to a different semantic concept, that of being a normal vector.</p>

<p>I wouldn&#8217;t use vectors and matrices just for exposition; they occur <em>everywhere</em> in scientific computing, where performance is critical and you can&#8217;t copy anything.  It would be nice to be able to say &#8220;once I modify this l-value, I can now guarantee (or drop a guarantee) that an object belongs to certain overload set, which will change how it is treated by the compiler after the modification point&#8221;.</p>

<p>For example, you tack some syntactic information onto the Vector3Impl::normalize method, so that upon returning it mutates (in some sense) the concept overload resolution of x, so that it can now be passed into the function &#8220;ThisOnlyTakesNormalVectors&#8221;.</p>

<p>I don&#8217;t know what to call this, or if its a very bad idea in the general case.  It is like &#8220;instance concepts&#8221; instead of &#8220;type concepts&#8221;.  It&#8217;s different than dynamic typing because the methods explain at compile time how they are changing the concept of the mutated object.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Jonas Persson</title>
		<link>http://cpp-next.com/archive/2009/08/three-kinds-of-concepts/comment-page-1/#comment-118</link>
		<dc:creator>Jonas Persson</dc:creator>
		<pubDate>Thu, 03 Sep 2009 15:51:13 +0000</pubDate>
		<guid isPermaLink="false">http://cpp-next.com/?p=253#comment-118</guid>
		<description>&lt;blockquote cite=&quot;comment-111&quot;&gt;

&lt;strong&gt;&lt;a href=&quot;#comment-111&quot; rel=&quot;nofollow&quot;&gt;Doug Gregor&lt;/a&gt;&lt;/strong&gt;: 
Contract programming was discussed in the committee and was ultimately rejected. Axioms were a much narrower feature meant to describe the semantics of concepts; we knew about the link with contract programming, but nobody seemed interested in pushing the idea forward as part of concepts or instead of axioms.No, there’s no notion of “the value previously held”.
&lt;/blockquote&gt;

&lt;p&gt;What were the reasons for rejecting contract programming? It is a commonly used, well understood
and very useful programming technique that could gain a lot from language
support. 
I can&#039;t see them as a replacement for axioms. They are independent features that could complement each other very well.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<blockquote cite="comment-111">

<strong><a href="#comment-111" rel="nofollow">Doug Gregor</a></strong>: 
Contract programming was discussed in the committee and was ultimately rejected. Axioms were a much narrower feature meant to describe the semantics of concepts; we knew about the link with contract programming, but nobody seemed interested in pushing the idea forward as part of concepts or instead of axioms.No, there’s no notion of “the value previously held”.
</blockquote>

<p>What were the reasons for rejecting contract programming? It is a commonly used, well understood
and very useful programming technique that could gain a lot from language
support. 
I can&#8217;t see them as a replacement for axioms. They are independent features that could complement each other very well.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Maxim Yanchenko</title>
		<link>http://cpp-next.com/archive/2009/08/three-kinds-of-concepts/comment-page-1/#comment-117</link>
		<dc:creator>Maxim Yanchenko</dc:creator>
		<pubDate>Thu, 03 Sep 2009 14:36:51 +0000</pubDate>
		<guid isPermaLink="false">http://cpp-next.com/?p=253#comment-117</guid>
		<description>&lt;blockquote cite=&quot;comment-116&quot;&gt;

&lt;strong&gt;&lt;a href=&quot;#comment-116&quot; rel=&quot;nofollow&quot;&gt;Dave Abrahams&lt;/a&gt;&lt;/strong&gt;: C++0x lambdas are actually a big disappointment to me
&lt;/blockquote&gt;

&lt;p&gt;I totally agree. But looks like polymorphic lambdas are to appear in the next Standard (hope it&#039;s not C++2x)?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<blockquote cite="comment-116">

<strong><a href="#comment-116" rel="nofollow">Dave Abrahams</a></strong>: C++0x lambdas are actually a big disappointment to me
</blockquote>

<p>I totally agree. But looks like polymorphic lambdas are to appear in the next Standard (hope it&#8217;s not C++2x)?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Abrahams</title>
		<link>http://cpp-next.com/archive/2009/08/three-kinds-of-concepts/comment-page-1/#comment-116</link>
		<dc:creator>Dave Abrahams</dc:creator>
		<pubDate>Wed, 02 Sep 2009 20:21:27 +0000</pubDate>
		<guid isPermaLink="false">http://cpp-next.com/?p=253#comment-116</guid>
		<description>&lt;blockquote cite=&quot;comment-109&quot;&gt;

&lt;strong&gt;&lt;a href=&quot;#comment-109&quot; rel=&quot;nofollow&quot;&gt;Brendan Miller&lt;/a&gt;&lt;/strong&gt;: Why would anyone in the real world cares about anything other than getting better errors from template libraries like the STL?&lt;/blockquote&gt;

&lt;p&gt;Hi Brendan,&lt;/p&gt;

&lt;p&gt;Thanks for asking.&lt;/p&gt;

&lt;p&gt;I always get nervous around questions about what &quot;anyone in the real world cares about,&quot; since the definition of &quot;real world&quot; is subjective, and although everyone &lt;em&gt;thinks&lt;/em&gt; they know what &quot;average C++ programmers&quot; care about, we don&#039;t have &lt;em&gt;any&lt;/em&gt; data.&lt;br /&gt;
That said, in the &quot;real world,&quot; some people:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;would like to write generic programs straightforwardly, without resorting to hacks like &lt;a href=&quot;http://www.generic-programming.org/languages/cpp/techniques.php#tag_dispatching&quot; rel=&quot;nofollow&quot;&gt;tag dispatching&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;would like to know that they have documented all the requirements of their templates without resorting to hacks like &lt;a href=&quot;http://www.boost.org/doc/libs/1_39_0/libs/concept_check/concept_covering.htm&quot; rel=&quot;nofollow&quot;&gt;concept archetypes&lt;/a&gt;; instead they&#039;d like the compiler to check for them automatically&lt;/li&gt;
&lt;li&gt;would like to have their templates completely checked &lt;em&gt;at the point of definition&lt;/em&gt; (similar to above point).&lt;/li&gt;
&lt;li&gt;would like to be able to use independently-developed types with generic libraries &lt;a href=&quot;http://www.generic-programming.org/languages/conceptcpp/tutorial/#adapting&quot; rel=&quot;nofollow&quot;&gt;without tedious type wrapping&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote cite=&quot;comment-109&quot;&gt;That seems to be satisfied well enough by the simple syntax checking case. Heck, static_assert seems like it does that.
&lt;/blockquote&gt;

&lt;p&gt;Even if you just care about better error messages for &lt;em&gt;uses&lt;/em&gt; of templates, using &lt;code&gt;static_assert&lt;/code&gt; to accomplish the same quality of error messages as you could get from concepts would be a &lt;em&gt;lot&lt;/em&gt; of work.&lt;/p&gt;

&lt;blockquote cite=&quot;comment-109&quot;&gt;
I saw in some older specs that you could specialize templates based on concept? Oh man, that was ridiculous. Who cares? How am I actually going to use that?
&lt;/blockquote&gt;

&lt;p&gt;You can write templates that are optimized based on the concepts satisfied by their template parameters.  We have plenty of examples of that today (e.g. &lt;code&gt;binary_search&lt;/code&gt; works on forward iterators, but is faster on random access iterators) , but today&#039;s examples use the hacks mentioned earlier.&lt;/p&gt;

&lt;blockquote cite=&quot;comment-109&quot;&gt;
Then were going to need some kind of concept_cast just to use the libraries.&lt;/blockquote&gt;

&lt;p&gt;Not sure what you have in mind when you say &quot;&lt;code&gt;concept_cast&lt;/code&gt;,&quot; but I don&#039;t think anything like that is needed.&lt;/p&gt;

&lt;blockquote cite=&quot;comment-109&quot;&gt;
I don’t really get what you mean by by constraining boost lambda. 
I never used that library since it was so ridiculous.  &lt;/blockquote&gt;

&lt;p&gt;Leaving aside the evil &lt;code&gt;late_check&lt;/code&gt; feature, any template you want to use inside concept-constrained code also needs to be concept-constrained.  So if you want to use a library like Boost.Lambda (or some features of Boost.Bind)---and many people do---in constrained code, that library had better also be constrained.&lt;/p&gt;

&lt;blockquote cite=&quot;comment-109&quot;&gt;It seems especially pointless now that C++ has actual lambda’s.
&lt;/blockquote&gt;

&lt;p&gt;C++0x lambdas are actually a big disappointment to me, because unlike Boost.Lambda they&#039;re not (compile-time) polymorphic.  I don&#039;t think&lt;/p&gt;

&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;cpp&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;span style=&quot;color: #008000;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;(&lt;/span&gt;foobar &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #000040;&quot;&gt;&amp;&lt;/span&gt; x, baz &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #000040;&quot;&gt;&amp;&lt;/span&gt; y&lt;span style=&quot;color: #008000;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;{&lt;/span&gt; x &lt;span style=&quot;color: #000040;&quot;&gt;+&lt;/span&gt;y &lt;span style=&quot;color: #008000;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;(or however it&#039;s spelled) can compete with&lt;/p&gt;

&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;cpp&quot; style=&quot;font-family:monospace;&quot;&gt;_1 &lt;span style=&quot;color: #000040;&quot;&gt;+&lt;/span&gt; _2&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;for usability or readability.&lt;/p&gt;

&lt;blockquote cite=&quot;comment-109&quot;&gt;
If you are arguing for more advanced concept features (I’m kind of unsure) maybe you could give a concrete example of how they would be used in actual application code? Right now the only use I see for concepts is that it saves typing over using static_assert.
&lt;/blockquote&gt;

&lt;p&gt;I&#039;m not arguing for more advanced concept features, but if you want some examples I suggest perusing the &lt;a href=&quot;http://www.generic-programming.org/languages/conceptcpp/&quot; rel=&quot;nofollow&quot;&gt;ConceptC++&lt;/a&gt; documentation.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<blockquote cite="comment-109">

<strong><a href="#comment-109" rel="nofollow">Brendan Miller</a></strong>: Why would anyone in the real world cares about anything other than getting better errors from template libraries like the STL?</blockquote>

<p>Hi Brendan,</p>

<p>Thanks for asking.</p>

<p>I always get nervous around questions about what &#8220;anyone in the real world cares about,&#8221; since the definition of &#8220;real world&#8221; is subjective, and although everyone <em>thinks</em> they know what &#8220;average C++ programmers&#8221; care about, we don&#8217;t have <em>any</em> data.<br />
That said, in the &#8220;real world,&#8221; some people:</p>

<ul>
<li>would like to write generic programs straightforwardly, without resorting to hacks like <a href="http://www.generic-programming.org/languages/cpp/techniques.php#tag_dispatching" rel="nofollow">tag dispatching</a></li>
<li>would like to know that they have documented all the requirements of their templates without resorting to hacks like <a href="http://www.boost.org/doc/libs/1_39_0/libs/concept_check/concept_covering.htm" rel="nofollow">concept archetypes</a>; instead they&#8217;d like the compiler to check for them automatically</li>
<li>would like to have their templates completely checked <em>at the point of definition</em> (similar to above point).</li>
<li>would like to be able to use independently-developed types with generic libraries <a href="http://www.generic-programming.org/languages/conceptcpp/tutorial/#adapting" rel="nofollow">without tedious type wrapping</a></li>
</ul>

<blockquote cite="comment-109">That seems to be satisfied well enough by the simple syntax checking case. Heck, static_assert seems like it does that.
</blockquote>

<p>Even if you just care about better error messages for <em>uses</em> of templates, using <code>static_assert</code> to accomplish the same quality of error messages as you could get from concepts would be a <em>lot</em> of work.</p>

<blockquote cite="comment-109">
I saw in some older specs that you could specialize templates based on concept? Oh man, that was ridiculous. Who cares? How am I actually going to use that?
</blockquote>

<p>You can write templates that are optimized based on the concepts satisfied by their template parameters.  We have plenty of examples of that today (e.g. <code>binary_search</code> works on forward iterators, but is faster on random access iterators) , but today&#8217;s examples use the hacks mentioned earlier.</p>

<blockquote cite="comment-109">
Then were going to need some kind of concept_cast just to use the libraries.</blockquote>

<p>Not sure what you have in mind when you say &#8220;<code>concept_cast</code>,&#8221; but I don&#8217;t think anything like that is needed.</p>

<blockquote cite="comment-109">
I don’t really get what you mean by by constraining boost lambda. 
I never used that library since it was so ridiculous.  </blockquote>

<p>Leaving aside the evil <code>late_check</code> feature, any template you want to use inside concept-constrained code also needs to be concept-constrained.  So if you want to use a library like Boost.Lambda (or some features of Boost.Bind)&#8212;and many people do&#8212;in constrained code, that library had better also be constrained.</p>

<blockquote cite="comment-109">It seems especially pointless now that C++ has actual lambda’s.
</blockquote>

<p>C++0x lambdas are actually a big disappointment to me, because unlike Boost.Lambda they&#8217;re not (compile-time) polymorphic.  I don&#8217;t think</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #008000;">[</span><span style="color: #008000;">]</span><span style="color: #008000;">(</span>foobar <span style="color: #0000ff;">const</span><span style="color: #000040;">&#038;</span> x, baz <span style="color: #0000ff;">const</span><span style="color: #000040;">&#038;</span> y<span style="color: #008000;">)</span> <span style="color: #008000;">{</span> x <span style="color: #000040;">+</span>y <span style="color: #008000;">}</span></pre></div></div>

<p>(or however it&#8217;s spelled) can compete with</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">_1 <span style="color: #000040;">+</span> _2</pre></div></div>

<p>for usability or readability.</p>

<blockquote cite="comment-109">
If you are arguing for more advanced concept features (I’m kind of unsure) maybe you could give a concrete example of how they would be used in actual application code? Right now the only use I see for concepts is that it saves typing over using static_assert.
</blockquote>

<p>I&#8217;m not arguing for more advanced concept features, but if you want some examples I suggest perusing the <a href="http://www.generic-programming.org/languages/conceptcpp/" rel="nofollow">ConceptC++</a> documentation.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Sebastian</title>
		<link>http://cpp-next.com/archive/2009/08/three-kinds-of-concepts/comment-page-1/#comment-114</link>
		<dc:creator>Sebastian</dc:creator>
		<pubDate>Wed, 02 Sep 2009 12:14:18 +0000</pubDate>
		<guid isPermaLink="false">http://cpp-next.com/?p=253#comment-114</guid>
		<description>&lt;p&gt;I&#039;m not 100% convinced that &quot;hole-free&quot; concept checking and performance are mutually exclusive. Concept checking is done in two places. (1) between constrained templates and archetypes, (2) within concept maps (N2914, section 40.10.2.1). The latter part is described in detail. Function requirements practically turn into expressions that have to be well-formed in order to render the concept-id satisfied. Checking between constrained templates and archetypes is less detailed. You once said that the function signatures are treated like normal functions. Ok, but that really doesn&#039;t match the rules of (2). It&#039;s not only about rvalues and lvalues. It&#039;s generally about conversions and the &quot;hidden parameter type&quot; of a function.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;pre&gt;concept Callable&lt;typename F, typename... Args&gt; &#123;
  typename result_type;
  result_type operator&#040;&#041;&#040;F &amp;, Args...&#041;;
  result_type operator&#040;&#041;&#040;F &amp;&amp;, Args...&#041;;
&#125;
struct A &#123;&#125;;
struct B &#123;operator A&#040;&#041; const;&#125;;
struct C &#123;operator B&#040;&#041; const;&#125;;
struct T &#123;
  void operator&#040;&#041;&#040;A&#041;;
&#125;;
&#160;
template&lt;typename F&gt; requires Callable&lt;F,B&gt;
void foo&#040;F &amp; f&#041; &#123;
  f&#040; C&#040;&#041; &#041;;
&#125;
&#160;
void bar&#040;&#041; &#123;
  T t;
  foo&#040;t&#041;;
&#125;&lt;/pre&gt;

&lt;p&gt;As far as I can tell this is another hole with the current rules. The function signature in Callable&lt;F,B&gt; suggests that we can invoke a function with a parameter that is implicitly convertible to B. This includes an object of type C. But C is not directly convertible to A. We would need two user-defined conversions to invoke T::operator() with an object of type C. This seems to result in another late instantiation error. On the other hand this function requirement implies an expression that is guaranteed to be well-formed: We can invoke the function with a parameter of type B that is an rvalue if B is not an lvalue reference. This is an inconsistency.
The problem here is that the constrained template doesn&#039;t know anything about whether the function takes actually a B or an A -- or a rvalue reference to a B in which case we don&#039;t need B to be MoveConstructible. The actual parameter type is &quot;hidden&quot; but we need to make sure that the object we pass is convertible to this hidden parameter type. But since it&#039;s &quot;hidden&quot; we can&#039;t express such a requirement.&lt;/p&gt;

&lt;p&gt;If we modified the rules for (1) to match the rules for (2) this constrained template would not type-check because Callable&lt;F,B&gt; would only guarantee that an F is callable with an rvalue of B as parameter. We should have written Callable&lt;F,C&gt; instead to make the constrained template well-formed. We just can&#039;t use it with F=T because Callable&lt;T,C&gt; is not satisfied.&lt;/p&gt;

&lt;p&gt;What I&#039;m saying is that I don&#039;t like the inconsistency between the checking rules for (1) and (2). Maybe function signatures are not the right tool for expressing syntactical requirements. Maybe it&#039;s worth trying &quot;expression requirements&quot; again.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I&#8217;m not 100% convinced that &#8220;hole-free&#8221; concept checking and performance are mutually exclusive. Concept checking is done in two places. (1) between constrained templates and archetypes, (2) within concept maps (N2914, section 40.10.2.1). The latter part is described in detail. Function requirements practically turn into expressions that have to be well-formed in order to render the concept-id satisfied. Checking between constrained templates and archetypes is less detailed. You once said that the function signatures are treated like normal functions. Ok, but that really doesn&#8217;t match the rules of (2). It&#8217;s not only about rvalues and lvalues. It&#8217;s generally about conversions and the &#8220;hidden parameter type&#8221; of a function.</p>

<p>Example:</p>

<pre>concept Callable&lt;typename F, typename... Args&gt; &#123;
  typename result_type;
  result_type operator&#40;&#41;&#40;F &amp;, Args...&#41;;
  result_type operator&#40;&#41;&#40;F &amp;&amp;, Args...&#41;;
&#125;
struct A &#123;&#125;;
struct B &#123;operator A&#40;&#41; const;&#125;;
struct C &#123;operator B&#40;&#41; const;&#125;;
struct T &#123;
  void operator&#40;&#41;&#40;A&#41;;
&#125;;
&nbsp;
template&lt;typename F&gt; requires Callable&lt;F,B&gt;
void foo&#40;F &amp; f&#41; &#123;
  f&#40; C&#40;&#41; &#41;;
&#125;
&nbsp;
void bar&#40;&#41; &#123;
  T t;
  foo&#40;t&#41;;
&#125;</pre>

<p>As far as I can tell this is another hole with the current rules. The function signature in Callable&lt;F,B&gt; suggests that we can invoke a function with a parameter that is implicitly convertible to B. This includes an object of type C. But C is not directly convertible to A. We would need two user-defined conversions to invoke T::operator() with an object of type C. This seems to result in another late instantiation error. On the other hand this function requirement implies an expression that is guaranteed to be well-formed: We can invoke the function with a parameter of type B that is an rvalue if B is not an lvalue reference. This is an inconsistency.
The problem here is that the constrained template doesn&#8217;t know anything about whether the function takes actually a B or an A &#8212; or a rvalue reference to a B in which case we don&#8217;t need B to be MoveConstructible. The actual parameter type is &#8220;hidden&#8221; but we need to make sure that the object we pass is convertible to this hidden parameter type. But since it&#8217;s &#8220;hidden&#8221; we can&#8217;t express such a requirement.</p>

<p>If we modified the rules for (1) to match the rules for (2) this constrained template would not type-check because Callable&lt;F,B&gt; would only guarantee that an F is callable with an rvalue of B as parameter. We should have written Callable&lt;F,C&gt; instead to make the constrained template well-formed. We just can&#8217;t use it with F=T because Callable&lt;T,C&gt; is not satisfied.</p>

<p>What I&#8217;m saying is that I don&#8217;t like the inconsistency between the checking rules for (1) and (2). Maybe function signatures are not the right tool for expressing syntactical requirements. Maybe it&#8217;s worth trying &#8220;expression requirements&#8221; again.</p>]]></content:encoded>
	</item>
</channel>
</rss>
