<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
	<title>Comparison operators in fold-expressions</title>

	<style>
	p {text-align:justify}
	li {text-align:justify}
	blockquote.note
	{
		background-color:#E0E0E0;
		padding-left: 15px;
		padding-right: 15px;
		padding-top: 1px;
		padding-bottom: 1px;
	}
	ins {color:#00A000}
	del {color:#A00000}
	</style>
</head>
<body>

<address align="right">
Document number: P0313R0
<br>
<br>
Target audience: EWG<br/>
<a href="mailto:ville.voutilainen@gmail.com">Ville Voutilainen</a><br>
2016-03-21<br>
</address>
<hr>
<h1 align="center">Comparison operators in fold-expressions</h1>

<h2>Abstract</h2>
<p>
  Comparison operators don't make much sense in fold-expressions;
  they expand into expressions that have surprising effects, and
  are thus useful for dsl-metaprogrammers only. This paper proposes
  removing comparison operators from the set of fold-operators.
</p>

<h2>Consistency</h2>
<p>
  It would be nice to be able to fix expressions like <code>a &lt; b &lt; c</code>. That would require a time machine. Not repeating the problem for
  fold-expressions seems doable.
</p>

<h2>Solution options</h2>

<p>
  The solution options I enumerated on the reflector were as follows:
</p>
<ol>
<li>it's fine, let's leave it be</li>
<li>remove all of <code>== != &lt; &gt; &lt;= &gt;=</code> from the list of supported fold-operators</li>
<li>redefine those fold-operators so that they produce a logical-and combination of individual comparisons</li>
</ol>
<p>
  Based on the reflector discussion, the last option might be tricky
  to specify, and might have surprising semantics. Some find having
  different semantics for it and the bare
  chain of multiple comparison operators potentially confusing. The safe
  choice is the second one. 
</p>

<h2>Rationale for removal</h2>

<p>
  There's no sane way to write a fold-expression using a comparison
  operator correctly. The way it works is not useful for non-expert
  programmers and is a source of surprise (based on real field
  experience). It's at best only a dsl-metaprogramming tool.
</p>

<h2>Wording</h2>

<p>
  In [expr.prim.fold]/1, edit as follows:
</p>
<p>
  <blockquote>
    fold-operator: one of<br/>
    <code>
      + - * / %  &amp; | &lt;&lt;  &gt;&gt;<br/>
      += -= *= /= %= = &amp;= |= &lt;&lt;= &gt;&gt;= =<br/>
      <del>== != &lt; &gt; &lt;= &gt;=</del> &amp;&amp; || , .* ->*
    </code>
  </blockquote>
</p>

</body></html>
