Boost C++ Libraries: Ticket #3215: Clamp function https://svn.boost.org/trac10/ticket/3215 <p> A clamp function comes in handy in certain cases. Could one be added to Boost? I'm not sure which component would be most appropriate. </p> <p> The function may be something like this: </p> <pre class="wiki">template&lt;class T&gt; T clamp(T v, T a, T b) { return max(a, min(v, b)); } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3215 Trac 1.4.3 Marshall Clow Sat, 27 Jun 2009 18:28:55 GMT status changed; owner set https://svn.boost.org/trac10/ticket/3215#comment:1 https://svn.boost.org/trac10/ticket/3215#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Marshall Clow</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket Marshall Clow Sat, 27 Jun 2009 23:13:20 GMT <link>https://svn.boost.org/trac10/ticket/3215#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3215#comment:2</guid> <description> <p> I just added "sandbox/boost/algorithm/clamp.hpp" Tests in "sandbox/libs/algorithm/clamp/test". </p> <p> Let me know if that's what you wanted. </p> </description> <category>Ticket</category> </item> <item> <author>OlafvdSpek@…</author> <pubDate>Sun, 28 Jun 2009 09:47:37 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3215#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3215#comment:3</guid> <description> <p> Yes, except you put the value at the back instead of at the front, I'm not sure that's preferable. </p> <p> Would it be better to use separate templated types for lo and hi to avoid the issues with std::max and std::min? The return type is clear in this case, the type of the original value. </p> </description> <category>Ticket</category> </item> <item> <author>OlafvdSpek@…</author> <pubDate>Sun, 28 Jun 2009 09:49:32 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3215#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3215#comment:4</guid> <description> <blockquote class="citation"> <p> return val &lt; lo ? lo : val &lt; hi ? val : hi; </p> </blockquote> <p> Should be: </p> <p> return val &lt; lo ? lo : hi &lt; val ? hi : val; </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Sun, 28 Jun 2009 17:24:44 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3215#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3215#comment:5</guid> <description> <p> I can see putting the value first, that's no problem. </p> <p> However, I don't see the difference in the two code snippets. When hi == val, the first one returns hi, and the second one returns val. When comparing objects, the first calls val.operator&lt; ( hi ), the second hi.operator&lt; ( val ). So? </p> </description> <category>Ticket</category> </item> <item> <author>Olaf van der Spek <OlafvdSpek@…></author> <pubDate>Sun, 28 Jun 2009 18:57:59 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3215#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3215#comment:6</guid> <description> <p> There is a difference when hi and val are equivalent but not equal. It's not an issue for simple types but it might be an issue in other cases. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Sun, 28 Jun 2009 23:05:42 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3215#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3215#comment:7</guid> <description> <p> Updated in the sandbox - revision 54484. </p> </description> <category>Ticket</category> </item> <item> <author>olafvdspek@…</author> <pubDate>Wed, 08 Jul 2009 09:19:47 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3215#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3215#comment:8</guid> <description> <p> Looks good. </p> </description> <category>Ticket</category> </item> <item> <author>olafvdspek@…</author> <pubDate>Wed, 08 Jul 2009 09:20:09 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3215#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3215#comment:9</guid> <description> <p> <a class="ext-link" href="https://svn.boost.org/svn/boost/sandbox/boost/algorithm/clamp.hpp"><span class="icon">​</span>https://svn.boost.org/svn/boost/sandbox/boost/algorithm/clamp.hpp</a> </p> </description> <category>Ticket</category> </item> <item> <author>olafvdspek@…</author> <pubDate>Wed, 22 Jul 2009 09:38:05 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/3215#comment:10 https://svn.boost.org/trac10/ticket/3215#comment:10 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.40.0</span> → <span class="trac-field-new">Boost 1.41.0</span> </li> </ul> <p> To which library will this function be added? </p> Ticket Marshall Clow Wed, 22 Jul 2009 20:48:13 GMT <link>https://svn.boost.org/trac10/ticket/3215#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3215#comment:11</guid> <description> <p> Boost.Algorithm; once it (the library) is reviewed and accepted. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 07 Jun 2010 09:51:31 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/3215#comment:12 https://svn.boost.org/trac10/ticket/3215#comment:12 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> This kind of request must be sent to the Boost ML, not the Trac. </p> <p> I propose to close this ticket as this is more related to new features to the forthcoming Algorithm library. </p> Ticket Olaf van der Spek Mon, 07 Jun 2010 12:32:37 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/3215#comment:13 https://svn.boost.org/trac10/ticket/3215#comment:13 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">invalid</span> </li> </ul> <blockquote class="citation"> <p> I propose to close this ticket </p> </blockquote> <p> Proposing isn't the same as doing... Why don't you reassign to the algorithm lib? </p> Ticket viboes Mon, 07 Jun 2010 14:38:35 GMT <link>https://svn.boost.org/trac10/ticket/3215#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3215#comment:14</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/3215#comment:13" title="Comment 13">Olaf van der Spek</a>: </p> <blockquote class="citation"> <blockquote class="citation"> <p> I propose to close this ticket </p> </blockquote> <p> Proposing isn't the same as doing... Why don't you reassign to the algorithm lib? </p> </blockquote> <p> There is no Algorithm library. So no need to make defects on libraries that doesn't exists. If you can not assign a component, maybe you should close the ticket yourself. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 07 Jun 2010 18:42:16 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3215#comment:15 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3215#comment:15</guid> <description> <p> It's a feature request, not a bug report. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Tue, 08 Jun 2010 08:27:28 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3215#comment:16 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3215#comment:16</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/3215#comment:15" title="Comment 15">anonymous</a>: </p> <blockquote class="citation"> <p> It's a feature request, not a bug report. </p> </blockquote> <p> There is Library Submissions for that, I think. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 08 Jun 2010 11:55:01 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3215#comment:17 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3215#comment:17</guid> <description> <p> No, that's for submitting a library, not for requesting a function. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Mon, 29 Nov 2010 15:38:44 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3215#comment:18 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3215#comment:18</guid> <description> <p> It is not useful to make a request that nobody can handle :) Please close it yourself. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 29 Nov 2010 15:40:05 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3215#comment:19 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3215#comment:19</guid> <description> <p> marshall appears to be handling it. What's the problem? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Mon, 29 Nov 2010 15:45:35 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3215#comment:20 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3215#comment:20</guid> <description> <p> The reason that I assigned this ticket to myself is that I have implemented this in the (proposed) Boost.Algorithms library, which I will post a version 0.1 on the man list "REAL SOON NOW". </p> </description> <category>Ticket</category> </item> <item> <author>sorokin@…</author> <pubDate>Mon, 21 Mar 2011 22:01:54 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3215#comment:21 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3215#comment:21</guid> <description> <p> So, will this function be included in boost? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Sun, 03 Apr 2011 03:51:27 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3215#comment:22 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3215#comment:22</guid> <description> <p> See &lt;<a class="ext-link" href="http://lists.boost.org/Archives/boost/2011/03/179561.php"><span class="icon">​</span>http://lists.boost.org/Archives/boost/2011/03/179561.php</a>&gt; </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Mon, 09 Jan 2012 18:27:13 GMT</pubDate> <title>component, milestone changed https://svn.boost.org/trac10/ticket/3215#comment:23 https://svn.boost.org/trac10/ticket/3215#comment:23 <ul> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">algorithm</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.41.0</span> → <span class="trac-field-new">Boost 1.50.0</span> </li> </ul> <p> Checked into trunk in <a class="changeset" href="https://svn.boost.org/trac10/changeset/76388" title="Initial checkin of Boost.Algorithm searching and clamp code and tests; ...">[76388]</a>. Will close ticket when merged to release (which will be for 1.50 release) </p> Ticket Marshall Clow Wed, 23 May 2012 16:25:51 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/3215#comment:24 https://svn.boost.org/trac10/ticket/3215#comment:24 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/78557" title="Merged changes for Boost.Algorithm to release; Fixes #6596; Fixes ...">[78557]</a>) Merged changes for Boost.Algorithm to release; Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6596" title="#6596: Bugs: Docs bug in boost_1_49_0_beta1/doc/html/boost/algorithm/find_head.html (closed: fixed)">#6596</a>; Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6689" title="#6689: Bugs: For String Algo's trim, documentation is misleading. (closed: fixed)">#6689</a>; Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3215" title="#3215: Feature Requests: Clamp function (closed: fixed)">#3215</a>; Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6840" title="#6840: Bugs: Mistake in Boost 1.49 String Algorithm Documentation (closed: fixed)">#6840</a> </p> Ticket Olaf van der Spek <olafvdspek@…> Tue, 19 Jun 2012 11:05:48 GMT <link>https://svn.boost.org/trac10/ticket/3215#comment:25 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3215#comment:25</guid> <description> <p> Is this supposed to be available in namespace boost or just in boost::algorithm? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Tue, 19 Jun 2012 13:08:31 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3215#comment:26 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3215#comment:26</guid> <description> <p> <code>boost::algorithm</code> </p> <p> All the algorithms in Boost.Algorithm are in that namespace. </p> </description> <category>Ticket</category> </item> <item> <author>Olaf van der Spek <olafvdspek@…></author> <pubDate>Tue, 19 Jun 2012 14:34:07 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3215#comment:27 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3215#comment:27</guid> <description> <p> Why's that? String functions, like to_upper, are in boost itself. </p> </description> <category>Ticket</category> </item> </channel> </rss>