Topic: Overload std::for_each for binary functions


Author: morwenn29@gmail.com
Date: Wed, 18 Sep 2013 05:28:44 -0700 (PDT)
Raw View
------=_Part_4324_15244141.1379507324117
Content-Type: text/plain; charset=ISO-8859-1

I sometimes - often - want to apply binary functions element-wise between
two ranges. In order to do so, it would be great to have
an overload of std::for_each for binary functions. It would be something
like this:

template<class InputIt1, class InputIt2 class BinaryFunction>
UnaryFunction for_each(InputIt1 first1, InputIt1 last1, InputIt2 first2, BinaryFunction f){
    for (; first1 != last1; ++first1, ++first2) {
        f(*first1, *first2);
    }
    return f;}


--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_4324_15244141.1379507324117
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I sometimes - often - want to apply binary functions eleme=
nt-wise between two ranges. In order to do so, it would be great to have<br=
>an overload of std::for_each for binary functions. It would be something l=
ike this:<br><br><div dir=3D"ltr" class=3D"mw-geshi" style=3D"text-align: l=
eft;"><div class=3D"cpp source-cpp"><pre class=3D"de1"><span class=3D"kw1">=
template</span><span class=3D"sy1">&lt;</span><span class=3D"kw1">class</sp=
an> InputIt1, class InputIt2 <span class=3D"kw1">class</span> BinaryFunctio=
n<span class=3D"sy1">&gt;</span>
UnaryFunction for_each<span class=3D"br0">(</span>InputIt1 first1, InputIt1=
 last1, InputIt2 first2, BinaryFunction f<span class=3D"br0">)</span>
<span class=3D"br0">{</span>
    <span class=3D"kw1">for</span> <span class=3D"br0">(</span><span class=
=3D"sy4">;</span> first1 <span class=3D"sy3">!</span><span class=3D"sy1">=
=3D</span> last1<span class=3D"sy4">;</span> <span class=3D"sy2">++</span>f=
irst1, ++first2<span class=3D"br0">)</span> <span class=3D"br0">{</span>
        f<span class=3D"br0">(</span><span class=3D"sy2">*</span>first<span=
 class=3D"br0">1, *first2)</span><span class=3D"sy4">;</span>
    <span class=3D"br0">}</span>
    <span class=3D"kw1">return</span> f<span class=3D"sy4">;</span>
<span class=3D"br0">}</span></pre></div></div><br></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_4324_15244141.1379507324117--

.


Author: "Billy O'Neal" <billy.oneal@gmail.com>
Date: Wed, 18 Sep 2013 08:35:53 -0700
Raw View
--001a11c1c93ab5362604e6aa33bb
Content-Type: text/plain; charset=ISO-8859-1

I'd assume you actually meant:

template<class InputIt1, class InputIt2, class BinaryFunction>
BinaryFunction for_each(InputIt1 first1, InputIt1 last1, InputIt2 first2,
BinaryFunction f)
{
    for (; first1 != last1; ++first1, ++first2) {
        f(*first1, *first2);
    }
    return f;
}

:)

I'd also like to add this:

template<class InputIt1, class InputIt2, class BinaryFunction>
BinaryFunction for_each(InputIt1 first1, InputIt1 last1, InputIt2 first2,
InputIt2 last2, BinaryFunction f)

With possible implementation + example:

http://ideone.com/UwSrbo

#include <vector>
#include <string>
#include <iostream>
#include <list>
using namespace std;

template<class InputIt1, class InputIt2, class BinaryFunction>
BinaryFunction for_each_impl(InputIt1 first1, InputIt1 last1, InputIt2
first2, InputIt2 last2, BinaryFunction f, std::random_access_iterator_tag,
std::random_access_iterator_tag)
{
    std::cout << "Optimized for random access.\n";
    if (last1 - first1 < last2 - first2)
    {
        for (; first1 != last1; ++first1, ++first2) {
            f(*first1, *first2);
        }
    }
    else
    {
        for (; first2 != last2; ++first1, ++first2) {
            f(*first1, *first2);
        }
    }

    return f;
}

template<class InputIt1, class InputIt2, class BinaryFunction>
BinaryFunction for_each_impl(InputIt1 first1, InputIt1 last1, InputIt2
first2, InputIt2 last2, BinaryFunction f, std::input_iterator_tag,
std::input_iterator_tag)
{
    std::cout << "Generic implementation.\n";
    for (; first1 != last1 && first2 != last2; ++first1, ++first2) {
        f(*first1, *first2);
    }
    return f;
}

template<class InputIt1, class InputIt2, class BinaryFunction>
BinaryFunction for_each(InputIt1 first1, InputIt1 last1, InputIt2 first2,
InputIt2 last2, BinaryFunction f)
{
    typedef typename std::iterator_traits<InputIt1>::iterator_category
Category1;
    typedef typename std::iterator_traits<InputIt2>::iterator_category
Category2;
    return for_each_impl(first1, last1, first2, last2, f, Category1(),
Category2());
}

template <template <typename, typename> class ContainerT>
void test()
{
    ContainerT<int, std::allocator<int>> example;
    example.push_back(42);
    example.push_back(1729);
    ContainerT<string, std::allocator<string>> example2;
    example2.push_back("forty two");
    example2.push_back("seventeen twenty nine");
    for_each(example.cbegin(), example.cend(), example2.cbegin(),
example2.cend(),
        [](int left, string const& right) { std::cout << left << " is " <<
right << "\n"; });
}

int main() {
    test<list>();
    test<vector>();
}


Billy O'Neal
https://github.com/BillyONeal/ <https://bitbucket.org/BillyONeal/>
http://stackoverflow.com/users/82320/billy-oneal
Malware Response Instructor - BleepingComputer.com


On Wed, Sep 18, 2013 at 5:28 AM, <morwenn29@gmail.com> wrote:

> I sometimes - often - want to apply binary functions element-wise between
> two ranges. In order to do so, it would be great to have
> an overload of std::for_each for binary functions. It would be something
> like this:
>
> template<class InputIt1, class InputIt2 class BinaryFunction>
> UnaryFunction for_each(InputIt1 first1, InputIt1 last1, InputIt2 first2, BinaryFunction f){
>     for (; first1 != last1; ++first1, ++first2) {
>         f(*first1, *first2);
>     }
>     return f;}
>
>
>  --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--001a11c1c93ab5362604e6aa33bb
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I&#39;d assume you actually meant:</div><div>=A0</div=
><div><font face=3D"courier new,monospace"><span>template</span><span>&lt;<=
/span><span>class</span> InputIt1, class InputIt2<font color=3D"#ff0000">,<=
/font> <span>class</span> BinaryFunction<span>&gt;</span><br>

<font color=3D"#ff0000">BinaryFunction </font>for_each<span>(</span>InputIt=
1 first1, InputIt1 last1, InputIt2 first2, BinaryFunction f<span>)</span><b=
r><span>{</span><br>=A0=A0=A0 <span>for</span> <span>(</span><span>;</span>=
 first1 <span>!</span><span>=3D</span> last1<span>;</span> <span>++</span>f=
irst1, ++first2<span>)</span> <span>{</span><br>

=A0=A0=A0=A0=A0=A0=A0 f<span>(</span><span>*</span>first<span>1, *first2)</=
span><span>;</span><br>=A0=A0=A0 <span>}</span><br>=A0=A0=A0 <span>return</=
span> f<span>;</span><br><span>}</span></font></div><div><span></span>=A0</=
div><div><span>:)</span></div>

<div><span></span>=A0</div><div><span>I&#39;d also like to add this:</span>=
</div><div><span></span>=A0</div><div><span><font face=3D"courier new,monos=
pace">template&lt;class InputIt1, class InputIt2, class BinaryFunction&gt;<=
br>

BinaryFunction for_each(InputIt1 first1, InputIt1 last1, InputIt2 first2, I=
nputIt2 last2, BinaryFunction f)</font></span></div><div><span></span>=A0</=
div><div><span>With possible implementation + example:</span></div><div>
<span></span>=A0</div>
<div><span><a href=3D"http://ideone.com/UwSrbo">http://ideone.com/UwSrbo</a=
></span></div><div><span></span><span></span>=A0</div><div><span><font face=
=3D"courier new,monospace">#include &lt;vector&gt;<br>#include &lt;string&g=
t;<br>

#include &lt;iostream&gt;<br>#include &lt;list&gt;<br>using namespace std;<=
/font></span></div><div><span><font face=3D"Courier New"></font></span>=A0<=
/div><div><span><font face=3D"courier new,monospace">template&lt;class Inpu=
tIt1, class InputIt2, class BinaryFunction&gt;<br>

BinaryFunction for_each_impl(InputIt1 first1, InputIt1 last1, InputIt2 firs=
t2, InputIt2 last2, BinaryFunction f, std::random_access_iterator_tag, std:=
:random_access_iterator_tag)<br>{<br>=A0=A0 =A0std::cout &lt;&lt; &quot;Opt=
imized for random access.\n&quot;;<br>

=A0=A0=A0 if (last1 - first1 &lt; last2 - first2)<br>=A0=A0=A0 {<br>=A0=A0=
=A0=A0=A0=A0=A0 for (; first1 !=3D last1; ++first1, ++first2) {<br>=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0 f(*first1, *first2);<br>=A0=A0=A0=A0=A0=A0=A0 }=
<br>=A0=A0=A0 }<br>=A0=A0=A0 else<br>=A0=A0=A0 {<br>=A0=A0=A0=A0=A0=A0=A0 f=
or (; first2 !=3D last2; ++first1, ++first2) {<br>

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 f(*first1, *first2);<br>=A0=A0=A0=A0=A0=
=A0=A0 }<br>=A0=A0=A0 }<br>=A0=A0=A0 <br>=A0=A0=A0 return f;<br>}</font></s=
pan></div><div><span><font face=3D"courier new,monospace"></font></span>=A0=
</div><div><span><font face=3D"courier new,monospace">template&lt;class Inp=
utIt1, class InputIt2, class BinaryFunction&gt;<br>

BinaryFunction for_each_impl(InputIt1 first1, InputIt1 last1, InputIt2 firs=
t2, InputIt2 last2, BinaryFunction f, std::input_iterator_tag, std::input_i=
terator_tag)<br>{<br>=A0=A0 =A0std::cout &lt;&lt; &quot;Generic implementat=
ion.\n&quot;;<br>

=A0=A0=A0 for (; first1 !=3D last1 &amp;&amp; first2 !=3D last2; ++first1, =
++first2) {<br>=A0=A0=A0=A0=A0=A0=A0 f(*first1, *first2);<br>=A0=A0=A0 }<br=
>=A0=A0=A0 return f;<br>}</font></span></div><div><span><font face=3D"couri=
er new,monospace"></font></span>=A0</div>

<div><span><font face=3D"courier new,monospace">template&lt;class InputIt1,=
 class InputIt2, class BinaryFunction&gt;<br>BinaryFunction for_each(InputI=
t1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, BinaryFunction =
f)<br>

{<br>=A0=A0=A0 typedef typename std::iterator_traits&lt;InputIt1&gt;::itera=
tor_category Category1;<br>=A0=A0=A0 typedef typename std::iterator_traits&=
lt;InputIt2&gt;::iterator_category Category2;<br>=A0=A0=A0 return for_each_=
impl(first1, last1, first2, last2, f, Category1(), Category2());<br>

}</font></span></div><div><span></span>=A0</div><div><span><font face=3D"co=
urier new,monospace">template &lt;template &lt;typename, typename&gt; class=
 ContainerT&gt;<br>void test()<br>{<br>=A0=A0 =A0ContainerT&lt;int, std::al=
locator&lt;int&gt;&gt; example;<br>

=A0=A0 =A0example.push_back(42);<br>=A0=A0=A0 example.push_back(1729);<br>=
=A0=A0=A0 ContainerT&lt;string, std::allocator&lt;string&gt;&gt; example2;<=
br>=A0=A0 =A0example2.push_back(&quot;forty two&quot;);<br>=A0=A0=A0 exampl=
e2.push_back(&quot;seventeen twenty nine&quot;);<br>

=A0=A0 =A0for_each(example.cbegin(), example.cend(), example2.cbegin(), exa=
mple2.cend(),<br>=A0=A0=A0=A0 =A0=A0 [](int left, string const&amp; right) =
{ std::cout &lt;&lt; left &lt;&lt; &quot; is &quot; &lt;&lt; right &lt;&lt;=
 &quot;\n&quot;; });<br>

}</font></span></div><div><span><font face=3D"Courier New"></font></span>=
=A0</div><div><span><font face=3D"courier new,monospace">int main() {</font=
></span><span><font face=3D"courier new,monospace"><br>=A0=A0=A0=A0test&lt;=
list&gt;();<br>

=A0=A0 =A0test&lt;vector&gt;();<br>}</font></span></div><div><span></span>=
=A0</div></div><div class=3D"gmail_extra"><br clear=3D"all"><div><div dir=
=3D"ltr"><div>Billy O&#39;Neal</div><div><a href=3D"https://bitbucket.org/B=
illyONeal/" target=3D"_blank">https://github.com/BillyONeal/</a></div>

<div><a href=3D"http://stackoverflow.com/users/82320/billy-oneal" target=3D=
"_blank">http://stackoverflow.com/users/82320/billy-oneal</a></div><div>Mal=
ware Response Instructor - BleepingComputer.com</div></div></div>
<br><br><div class=3D"gmail_quote">On Wed, Sep 18, 2013 at 5:28 AM,  <span =
dir=3D"ltr">&lt;<a href=3D"mailto:morwenn29@gmail.com" target=3D"_blank">mo=
rwenn29@gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote=
" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir=3D"ltr">I sometimes - often - want to apply binary functions eleme=
nt-wise between two ranges. In order to do so, it would be great to have<br=
>an overload of std::for_each for binary functions. It would be something l=
ike this:<br>

<br><div style=3D"text-align:left" dir=3D"ltr"><div><pre><span>template</sp=
an><span>&lt;</span><span>class</span> InputIt1, class InputIt2 <span>class=
</span> BinaryFunction<span>&gt;</span>
UnaryFunction for_each<span>(</span>InputIt1 first1, InputIt1 last1, InputI=
t2 first2, BinaryFunction f<span>)</span>
<span>{</span>
    <span>for</span> <span>(</span><span>;</span> first1 <span>!</span><spa=
n>=3D</span> last1<span>;</span> <span>++</span>first1, ++first2<span>)</sp=
an> <span>{</span>
        f<span>(</span><span>*</span>first<span>1, *first2)</span><span>;</=
span>
    <span>}</span>
    <span>return</span> f<span>;</span>
<span>}</span></pre></div></div><span class=3D"HOEnZb"><font color=3D"#8888=
88"><br></font></span></div><span class=3D"HOEnZb"><font color=3D"#888888">

<p></p>

-- <br>
=A0<br>
--- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org" target=3D=
"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</font></span></blockquote></div><br></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--001a11c1c93ab5362604e6aa33bb--

.


Author: Nevin Liber <nevin@eviloverlord.com>
Date: Wed, 18 Sep 2013 10:42:40 -0500
Raw View
--001a11c3612afa96b904e6aa4b62
Content-Type: text/plain; charset=ISO-8859-1

On 18 September 2013 07:28, <morwenn29@gmail.com> wrote:

> I sometimes - often - want to apply binary functions element-wise between
> two ranges. In order to do so, it would be great to have
> an overload of std::for_each for binary functions.
>


1.  Why just binary?  Why not n-ary?

2.  Does it have to be named std::for_each?

--
 Nevin ":-)" Liber  <mailto:nevin@eviloverlord.com>  (847) 691-1404

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--001a11c3612afa96b904e6aa4b62
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On 18 September 2013 07:28,  <span dir=3D"ltr">&lt;<a href=
=3D"mailto:morwenn29@gmail.com" target=3D"_blank">morwenn29@gmail.com</a>&g=
t;</span> wrote:<br><div class=3D"gmail_extra"><div class=3D"gmail_quote"><=
blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px=
 #ccc solid;padding-left:1ex">

<div dir=3D"ltr">I sometimes - often - want to apply binary functions eleme=
nt-wise between two ranges. In order to do so, it would be great to have<br=
>an overload of std::for_each for binary functions. </div></blockquote><div=
>

<br><br></div><div>1.=A0 Why just binary?=A0 Why not n-ary?<br><br></div><d=
iv>2.=A0 Does it have to be named std::for_each?<br clear=3D"all"></div></d=
iv><br>-- <br>=A0Nevin &quot;:-)&quot; Liber=A0 &lt;mailto:<a href=3D"mailt=
o:nevin@eviloverlord.com" target=3D"_blank">nevin@eviloverlord.com</a>&gt;=
=A0 (847) 691-1404
</div></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--001a11c3612afa96b904e6aa4b62--

.


Author: morwenn29@gmail.com
Date: Wed, 18 Sep 2013 10:57:06 -0700 (PDT)
Raw View
------=_Part_55_8082278.1379527026625
Content-Type: text/plain; charset=ISO-8859-1

@Nevin: I had a problem I could solve with std::transform but which would
have been more conveniently solved with a binary std::for_each.
Since std::transform only works with unary and binary functors, I thought
std::for_each could also have a useful binary overload, but did
not think it further. I didn't check, but there are probably several other
algorithms that could have a n-ary overload and don't have it. Also,
I kept the name std::for_each instead of choosing a new one since the logic
involved is pretty much the same :)

@Billy: You're totally right about the two mistakes I made. I didn't have
my code at hand and hastily wrote this one while I should have
taken more time to avoid the errors. I don't know whether the parameter
last2 is useful though; std::transform does not have it for
example.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_55_8082278.1379527026625
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">@Nevin: I had a problem I could solve with std::transform =
but which would have been more conveniently solved with a binary std::for_e=
ach.<br>Since std::transform only works with unary and binary functors, I t=
hought std::for_each could also have a useful binary overload, but did<br>n=
ot think it further. I didn't check, but there are probably several other a=
lgorithms that could have a n-ary overload and don't have it. Also,<br>I ke=
pt the name std::for_each instead of choosing a new one since the logic inv=
olved is pretty much the same :)<br><br>@Billy: You're totally right about =
the two mistakes I made. I didn't have my code at hand and hastily wrote th=
is one while I should have<br>taken more time to avoid the errors. I don't =
know whether the parameter last2 is useful though; std::transform does not =
have it for<br>example.<br></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_55_8082278.1379527026625--

.


Author: "Billy O'Neal" <billy.oneal@gmail.com>
Date: Wed, 18 Sep 2013 12:17:04 -0700
Raw View
--047d7b3a9b12bd989904e6ad4ae5
Content-Type: text/plain; charset=ISO-8859-1

@morwenn29:



All the non-mutating algorithms accepting two ranges have variants
accepting both iterators for the second range in N3691. (That is, mismatch,
find, is_permutation, and equal) Consider 25.2.11 [alg.equal]:



template<class InputIterator1, class InputIterator2>
bool equal(InputIterator1 first1, InputIterator1 last1,
           InputIterator2 first2);

template<class InputIterator1, class InputIterator2, class BinaryPredicate>
bool equal(InputIterator1 first1, InputIterator1 last1,
           InputIterator2 first2, BinaryPredicate pred);

template<class InputIterator1, class InputIterator2>
bool equal(InputIterator1 first1, InputIterator1 last1,
           InputIterator2 first2, InputIterator2 last2);

template<class InputIterator1, class InputIterator2, class BinaryPredicate>
bool equal(InputIterator1 first1, InputIterator1 last1,

           InputIterator2 first2, InputIterator2 last2,
           BinaryPredicate pred);



Billy O'Neal
https://github.com/BillyONeal/ <https://bitbucket.org/BillyONeal/>
http://stackoverflow.com/users/82320/billy-oneal
Malware Response Instructor - BleepingComputer.com


On Wed, Sep 18, 2013 at 10:57 AM, <morwenn29@gmail.com> wrote:

> @Nevin: I had a problem I could solve with std::transform but which would
> have been more conveniently solved with a binary std::for_each.
> Since std::transform only works with unary and binary functors, I thought
> std::for_each could also have a useful binary overload, but did
> not think it further. I didn't check, but there are probably several other
> algorithms that could have a n-ary overload and don't have it. Also,
> I kept the name std::for_each instead of choosing a new one since the
> logic involved is pretty much the same :)
>
> @Billy: You're totally right about the two mistakes I made. I didn't have
> my code at hand and hastily wrote this one while I should have
> taken more time to avoid the errors. I don't know whether the parameter
> last2 is useful though; std::transform does not have it for
> example.
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--047d7b3a9b12bd989904e6ad4ae5
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><div><table cellpadding=3D"0"><tbody><tr><td><table c=
ellpadding=3D"0"><tbody><tr><td><p>@morwenn29:</p><p>=A0</p><p>All the non-=
mutating algorithms accepting two ranges have variants accepting both itera=
tors for the second range in N3691. (That is, mismatch, find, is_permutatio=
n, and equal) Consider 25.2.11 [alg.equal]:</p>

<p>=A0</p><p><font face=3D"courier new,monospace">template&lt;class InputIt=
erator1, class InputIterator2&gt;<br>bool equal(InputIterator1 first1, Inpu=
tIterator1 last1,<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 InputIterator2 first2);=
<br><br>template&lt;class InputIterator1, class InputIterator2, class Binar=
yPredicate&gt;<br>

bool equal(InputIterator1 first1, InputIterator1 last1,<br>=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0 InputIterator2 first2, BinaryPredicate pred);<br></font></p=
><p><font face=3D"courier new,monospace">template&lt;class InputIterator1, =
class InputIterator2&gt;<br>

bool equal(InputIterator1 first1, InputIterator1 last1,<br>=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0 InputIterator2 first2, InputIterator2 last2);<br></font></p=
><p><font face=3D"courier new,monospace">template&lt;class InputIterator1, =
class InputIterator2, class BinaryPredicate&gt;<br>

bool equal(InputIterator1 first1, InputIterator1 last1,</font></p><p><font =
face=3D"courier new,monospace">=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 InputIterator=
2 first2, InputIterator2 last2,<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0BinaryP=
redicate pred);</font></p><p>=A0</p></td>
</tr>
</tbody></table></td></tr></tbody></table></div></div></div><div class=3D"g=
mail_extra"><br clear=3D"all"><div><div dir=3D"ltr"><div>Billy O&#39;Neal</=
div><div><a href=3D"https://bitbucket.org/BillyONeal/" target=3D"_blank">ht=
tps://github.com/BillyONeal/</a></div>

<div><a href=3D"http://stackoverflow.com/users/82320/billy-oneal" target=3D=
"_blank">http://stackoverflow.com/users/82320/billy-oneal</a></div><div>Mal=
ware Response Instructor - BleepingComputer.com</div></div></div>
<br><br><div class=3D"gmail_quote">On Wed, Sep 18, 2013 at 10:57 AM,  <span=
 dir=3D"ltr">&lt;<a href=3D"mailto:morwenn29@gmail.com" target=3D"_blank">m=
orwenn29@gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quot=
e" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir=3D"ltr">@Nevin: I had a problem I could solve with std::transform =
but which would have been more conveniently solved with a binary std::for_e=
ach.<br>Since std::transform only works with unary and binary functors, I t=
hought std::for_each could also have a useful binary overload, but did<br>

not think it further. I didn&#39;t check, but there are probably several ot=
her algorithms that could have a n-ary overload and don&#39;t have it. Also=
,<br>I kept the name std::for_each instead of choosing a new one since the =
logic involved is pretty much the same :)<br>

<br>@Billy: You&#39;re totally right about the two mistakes I made. I didn&=
#39;t have my code at hand and hastily wrote this one while I should have<b=
r>taken more time to avoid the errors. I don&#39;t know whether the paramet=
er last2 is useful though; std::transform does not have it for<br>

example.<br></div><div class=3D"HOEnZb"><div class=3D"h5">

<p></p>

-- <br>
=A0<br>
--- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org" target=3D=
"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></blockquote></div><br></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--047d7b3a9b12bd989904e6ad4ae5--

.


Author: "Bryan St. Amour" <bryan.stamour@gmail.com>
Date: Wed, 18 Sep 2013 12:24:03 -0700 (PDT)
Raw View
------=_Part_113_27927494.1379532243935
Content-Type: text/plain; charset=ISO-8859-1

Binary std::for_each is different than the other non-mutating algorithms
however, because as a precondition there should be at least as many
elements in [first2, last2) than there are in [first1, last1), just like
std::transform. My personal opinion is that binary std::for_each should not
take in last2 as a parameter.

On Wednesday, 18 September 2013 15:17:04 UTC-4, Billy O'Neal wrote:
>
> @morwenn29:
>
>
>
> All the non-mutating algorithms accepting two ranges have variants
> accepting both iterators for the second range in N3691. (That is, mismatch,
> find, is_permutation, and equal) Consider 25.2.11 [alg.equal]:
>
>
>
> template<class InputIterator1, class InputIterator2>
> bool equal(InputIterator1 first1, InputIterator1 last1,
>            InputIterator2 first2);
>
> template<class InputIterator1, class InputIterator2, class BinaryPredicate>
> bool equal(InputIterator1 first1, InputIterator1 last1,
>            InputIterator2 first2, BinaryPredicate pred);
>
> template<class InputIterator1, class InputIterator2>
> bool equal(InputIterator1 first1, InputIterator1 last1,
>            InputIterator2 first2, InputIterator2 last2);
>
> template<class InputIterator1, class InputIterator2, class BinaryPredicate>
> bool equal(InputIterator1 first1, InputIterator1 last1,
>
>            InputIterator2 first2, InputIterator2 last2,
>            BinaryPredicate pred);
>
>
>
> Billy O'Neal
> https://github.com/BillyONeal/ <https://bitbucket.org/BillyONeal/>
> http://stackoverflow.com/users/82320/billy-oneal
> Malware Response Instructor - BleepingComputer.com
>
>
> On Wed, Sep 18, 2013 at 10:57 AM, <morw...@gmail.com <javascript:>> wrote:
>
>> @Nevin: I had a problem I could solve with std::transform but which would
>> have been more conveniently solved with a binary std::for_each.
>> Since std::transform only works with unary and binary functors, I thought
>> std::for_each could also have a useful binary overload, but did
>> not think it further. I didn't check, but there are probably several
>> other algorithms that could have a n-ary overload and don't have it. Also,
>> I kept the name std::for_each instead of choosing a new one since the
>> logic involved is pretty much the same :)
>>
>> @Billy: You're totally right about the two mistakes I made. I didn't have
>> my code at hand and hastily wrote this one while I should have
>> taken more time to avoid the errors. I don't know whether the parameter
>> last2 is useful though; std::transform does not have it for
>> example.
>>
>> --
>>
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to std-proposal...@isocpp.org <javascript:>.
>> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
>> Visit this group at
>> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>>
>
>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_113_27927494.1379532243935
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Binary std::for_each is different than the other non-mutat=
ing algorithms however, because as a precondition there should be at least =
as many elements in [first2, last2) than there are in [first1, last1), just=
 like std::transform. My personal opinion is that binary std::for_each shou=
ld not take in last2 as a parameter.<br><br>On Wednesday, 18 September 2013=
 15:17:04 UTC-4, Billy O'Neal  wrote:<blockquote class=3D"gmail_quote" styl=
e=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left:=
 1ex;"><div dir=3D"ltr"><div><div><table cellpadding=3D"0"><tbody><tr><td><=
table cellpadding=3D"0"><tbody><tr><td><p>@morwenn29:</p><p>&nbsp;</p><p>Al=
l the non-mutating algorithms accepting two ranges have variants accepting =
both iterators for the second range in N3691. (That is, mismatch, find, is_=
permutation, and equal) Consider 25.2.11 [alg.equal]:</p>

<p>&nbsp;</p><p><font face=3D"courier new,monospace">template&lt;class Inpu=
tIterator1, class InputIterator2&gt;<br>bool equal(InputIterator1 first1, I=
nputIterator1 last1,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp; InputIterator2 first2);<br><br>template&lt;class InputIterator1, =
class InputIterator2, class BinaryPredicate&gt;<br>

bool equal(InputIterator1 first1, InputIterator1 last1,<br>&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InputIterator2 first2, BinaryP=
redicate pred);<br></font></p><p><font face=3D"courier new,monospace">templ=
ate&lt;class InputIterator1, class InputIterator2&gt;<br>

bool equal(InputIterator1 first1, InputIterator1 last1,<br>&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InputIterator2 first2, InputIt=
erator2 last2);<br></font></p><p><font face=3D"courier new,monospace">templ=
ate&lt;class InputIterator1, class InputIterator2, class BinaryPredicate&gt=
;<br>

bool equal(InputIterator1 first1, InputIterator1 last1,</font></p><p><font =
face=3D"courier new,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp; InputIterator2 first2, InputIterator2 last2,<br>&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BinaryPredicate pre=
d);</font></p><p>&nbsp;</p></td>
</tr>
</tbody></table></td></tr></tbody></table></div></div></div><div><br clear=
=3D"all"><div><div dir=3D"ltr"><div>Billy O'Neal</div><div><a href=3D"https=
://bitbucket.org/BillyONeal/" target=3D"_blank">https://github.com/BillyONe=
al/</a></div>

<div><a href=3D"http://stackoverflow.com/users/82320/billy-oneal" target=3D=
"_blank">http://stackoverflow.com/<wbr>users/82320/billy-oneal</a></div><di=
v>Malware Response Instructor - BleepingComputer.com</div></div></div>
<br><br><div class=3D"gmail_quote">On Wed, Sep 18, 2013 at 10:57 AM,  <span=
 dir=3D"ltr">&lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-m=
ailto=3D"RlzqKymZ8jUJ">morw...@gmail.com</a>&gt;</span> wrote:<br><blockquo=
te class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc so=
lid;padding-left:1ex">

<div dir=3D"ltr">@Nevin: I had a problem I could solve with std::transform =
but which would have been more conveniently solved with a binary std::for_e=
ach.<br>Since std::transform only works with unary and binary functors, I t=
hought std::for_each could also have a useful binary overload, but did<br>

not think it further. I didn't check, but there are probably several other =
algorithms that could have a n-ary overload and don't have it. Also,<br>I k=
ept the name std::for_each instead of choosing a new one since the logic in=
volved is pretty much the same :)<br>

<br>@Billy: You're totally right about the two mistakes I made. I didn't ha=
ve my code at hand and hastily wrote this one while I should have<br>taken =
more time to avoid the errors. I don't know whether the parameter last2 is =
useful though; std::transform does not have it for<br>

example.<br></div><div><div>

<p></p>

-- <br>
&nbsp;<br>
--- <br>
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
RlzqKymZ8jUJ">std-proposal...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"RlzqKymZ8jUJ">std-pr...@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/<wbr>isocpp.or=
g/group/std-<wbr>proposals/</a>.<br>
</div></div></blockquote></div><br></div>
</blockquote></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_113_27927494.1379532243935--

.


Author: Bengt Gustafsson <bengt.gustafsson@beamways.com>
Date: Wed, 18 Sep 2013 13:10:26 -0700 (PDT)
Raw View
------=_Part_45_22958168.1379535026748
Content-Type: text/plain; charset=ISO-8859-1

Can't this be done for any arity using variadic templates:

template<typename Function, typename InputIterator1, typename...
InputIterators> Function for_each(InputIterator1 first1, InputITerator1
last1, InputIterators... firsts, Function f);

This will require a helper variadic function to increment all the first
iterators, but that should not be a problem.

On the other hand this does not go well with supplying all the end
iterators unless we pass all the firsts and then all the lasts. Or can you
put the ... like this to get pairs of iterator parameters, I'm uncertain
ablout the comma there:

template<typename Function, typename... InputIterators> Function
for_each(InputIterators first1, InputITerators last1..., Function f);


Den onsdagen den 18:e september 2013 kl. 21:24:03 UTC+2 skrev Bryan St.
Amour:
>
> Binary std::for_each is different than the other non-mutating algorithms
> however, because as a precondition there should be at least as many
> elements in [first2, last2) than there are in [first1, last1), just like
> std::transform. My personal opinion is that binary std::for_each should not
> take in last2 as a parameter.
>
> On Wednesday, 18 September 2013 15:17:04 UTC-4, Billy O'Neal wrote:
>>
>> @morwenn29:
>>
>>
>>
>> All the non-mutating algorithms accepting two ranges have variants
>> accepting both iterators for the second range in N3691. (That is, mismatch,
>> find, is_permutation, and equal) Consider 25.2.11 [alg.equal]:
>>
>>
>>
>> template<class InputIterator1, class InputIterator2>
>> bool equal(InputIterator1 first1, InputIterator1 last1,
>>            InputIterator2 first2);
>>
>> template<class InputIterator1, class InputIterator2, class
>> BinaryPredicate>
>> bool equal(InputIterator1 first1, InputIterator1 last1,
>>            InputIterator2 first2, BinaryPredicate pred);
>>
>> template<class InputIterator1, class InputIterator2>
>> bool equal(InputIterator1 first1, InputIterator1 last1,
>>            InputIterator2 first2, InputIterator2 last2);
>>
>> template<class InputIterator1, class InputIterator2, class
>> BinaryPredicate>
>> bool equal(InputIterator1 first1, InputIterator1 last1,
>>
>>            InputIterator2 first2, InputIterator2 last2,
>>            BinaryPredicate pred);
>>
>>
>>
>> Billy O'Neal
>> https://github.com/BillyONeal/ <https://bitbucket.org/BillyONeal/>
>> http://stackoverflow.com/users/82320/billy-oneal
>> Malware Response Instructor - BleepingComputer.com
>>
>>
>> On Wed, Sep 18, 2013 at 10:57 AM, <morw...@gmail.com> wrote:
>>
>>> @Nevin: I had a problem I could solve with std::transform but which
>>> would have been more conveniently solved with a binary std::for_each.
>>> Since std::transform only works with unary and binary functors, I
>>> thought std::for_each could also have a useful binary overload, but did
>>> not think it further. I didn't check, but there are probably several
>>> other algorithms that could have a n-ary overload and don't have it. Also,
>>> I kept the name std::for_each instead of choosing a new one since the
>>> logic involved is pretty much the same :)
>>>
>>> @Billy: You're totally right about the two mistakes I made. I didn't
>>> have my code at hand and hastily wrote this one while I should have
>>> taken more time to avoid the errors. I don't know whether the parameter
>>> last2 is useful though; std::transform does not have it for
>>> example.
>>>
>>> --
>>>
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "ISO C++ Standard - Future Proposals" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to std-proposal...@isocpp.org.
>>> To post to this group, send email to std-pr...@isocpp.org.
>>> Visit this group at
>>> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>>>
>>
>>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_45_22958168.1379535026748
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Can't this be done for any arity using variadic templates:=
<div><br></div><div>template&lt;typename Function, typename InputIterator1,=
 typename... InputIterators&gt; Function for_each(InputIterator1 first1, In=
putITerator1 last1, InputIterators... firsts, Function f);</div><div><br></=
div><div>This will require a helper variadic function to increment all the =
first iterators, but that should not be a problem.</div><div><br></div><div=
>On the other hand this does not go well with supplying all the end iterato=
rs unless we pass all the firsts and then all the lasts. Or can you put the=
 ... like this to get pairs of iterator parameters, I'm uncertain ablout th=
e comma there:</div><div><br></div><div><div>template&lt;typename Function,=
 typename... InputIterators&gt; Function for_each(InputIterators first1, In=
putITerators last1..., Function f);</div><div><br></div><br>Den onsdagen de=
n 18:e september 2013 kl. 21:24:03 UTC+2 skrev Bryan St. Amour:<blockquote =
class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1p=
x #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">Binary std::for_each is d=
ifferent than the other non-mutating algorithms however, because as a preco=
ndition there should be at least as many elements in [first2, last2) than t=
here are in [first1, last1), just like std::transform. My personal opinion =
is that binary std::for_each should not take in last2 as a parameter.<br><b=
r>On Wednesday, 18 September 2013 15:17:04 UTC-4, Billy O'Neal  wrote:<bloc=
kquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-lef=
t:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div><table cellpa=
dding=3D"0"><tbody><tr><td><table cellpadding=3D"0"><tbody><tr><td><p>@morw=
enn29:</p><p>&nbsp;</p><p>All the non-mutating algorithms accepting two ran=
ges have variants accepting both iterators for the second range in N3691. (=
That is, mismatch, find, is_permutation, and equal) Consider 25.2.11 [alg.e=
qual]:</p>

<p>&nbsp;</p><p><font face=3D"courier new,monospace">template&lt;class Inpu=
tIterator1, class InputIterator2&gt;<br>bool equal(InputIterator1 first1, I=
nputIterator1 last1,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp; InputIterator2 first2);<br><br>template&lt;class InputIterator1, =
class InputIterator2, class BinaryPredicate&gt;<br>

bool equal(InputIterator1 first1, InputIterator1 last1,<br>&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InputIterator2 first2, BinaryP=
redicate pred);<br></font></p><p><font face=3D"courier new,monospace">templ=
ate&lt;class InputIterator1, class InputIterator2&gt;<br>

bool equal(InputIterator1 first1, InputIterator1 last1,<br>&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InputIterator2 first2, InputIt=
erator2 last2);<br></font></p><p><font face=3D"courier new,monospace">templ=
ate&lt;class InputIterator1, class InputIterator2, class BinaryPredicate&gt=
;<br>

bool equal(InputIterator1 first1, InputIterator1 last1,</font></p><p><font =
face=3D"courier new,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp; InputIterator2 first2, InputIterator2 last2,<br>&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BinaryPredicate pre=
d);</font></p><p>&nbsp;</p></td>
</tr>
</tbody></table></td></tr></tbody></table></div></div></div><div><br clear=
=3D"all"><div><div dir=3D"ltr"><div>Billy O'Neal</div><div><a href=3D"https=
://bitbucket.org/BillyONeal/" target=3D"_blank">https://github.com/BillyONe=
al/</a></div>

<div><a href=3D"http://stackoverflow.com/users/82320/billy-oneal" target=3D=
"_blank">http://stackoverflow.com/<wbr>users/82320/billy-oneal</a></div><di=
v>Malware Response Instructor - BleepingComputer.com</div></div></div>
<br><br><div class=3D"gmail_quote">On Wed, Sep 18, 2013 at 10:57 AM,  <span=
 dir=3D"ltr">&lt;<a>morw...@gmail.com</a>&gt;</span> wrote:<br><blockquote =
class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid=
;padding-left:1ex">

<div dir=3D"ltr">@Nevin: I had a problem I could solve with std::transform =
but which would have been more conveniently solved with a binary std::for_e=
ach.<br>Since std::transform only works with unary and binary functors, I t=
hought std::for_each could also have a useful binary overload, but did<br>

not think it further. I didn't check, but there are probably several other =
algorithms that could have a n-ary overload and don't have it. Also,<br>I k=
ept the name std::for_each instead of choosing a new one since the logic in=
volved is pretty much the same :)<br>

<br>@Billy: You're totally right about the two mistakes I made. I didn't ha=
ve my code at hand and hastily wrote this one while I should have<br>taken =
more time to avoid the errors. I don't know whether the parameter last2 is =
useful though; std::transform does not have it for<br>

example.<br></div><div><div>

<p></p>

-- <br>
&nbsp;<br>
--- <br>
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a>std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a>std-pr...@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/<wbr>isocpp.or=
g/group/std-<wbr>proposals/</a>.<br>
</div></div></blockquote></div><br></div>
</blockquote></div></blockquote></div></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_45_22958168.1379535026748--

.


Author: "Bryan St. Amour" <bryan.stamour@gmail.com>
Date: Wed, 18 Sep 2013 13:35:34 -0700 (PDT)
Raw View
------=_Part_216_13262601.1379536534306
Content-Type: text/plain; charset=ISO-8859-1

Not quite. The variadic pack has to come at the end of the parameter list,
so if you put the function first, then yeah that will work. But it breaks
with the traditional order of parameters in the STL. I think the best you
can do to support a variadic for_each is to pass the begin iterators in as
a tuple,and specify a last iterator to constrain the size of the range,
followed by the function. i.e.

    template <typename Iter, typename Func, typename... Iters>
    for_each(std::tuple<Iter, Iters...> firsts, Iter last, Func f);

On Wednesday, 18 September 2013 16:10:26 UTC-4, Bengt Gustafsson wrote:
>
> Can't this be done for any arity using variadic templates:
>
> template<typename Function, typename InputIterator1, typename...
> InputIterators> Function for_each(InputIterator1 first1, InputITerator1
> last1, InputIterators... firsts, Function f);
>
> This will require a helper variadic function to increment all the first
> iterators, but that should not be a problem.
>
> On the other hand this does not go well with supplying all the end
> iterators unless we pass all the firsts and then all the lasts. Or can you
> put the ... like this to get pairs of iterator parameters, I'm uncertain
> ablout the comma there:
>
> template<typename Function, typename... InputIterators> Function
> for_each(InputIterators first1, InputITerators last1..., Function f);
>
>
> Den onsdagen den 18:e september 2013 kl. 21:24:03 UTC+2 skrev Bryan St.
> Amour:
>>
>> Binary std::for_each is different than the other non-mutating algorithms
>> however, because as a precondition there should be at least as many
>> elements in [first2, last2) than there are in [first1, last1), just like
>> std::transform. My personal opinion is that binary std::for_each should not
>> take in last2 as a parameter.
>>
>> On Wednesday, 18 September 2013 15:17:04 UTC-4, Billy O'Neal wrote:
>>>
>>> @morwenn29:
>>>
>>>
>>>
>>> All the non-mutating algorithms accepting two ranges have variants
>>> accepting both iterators for the second range in N3691. (That is, mismatch,
>>> find, is_permutation, and equal) Consider 25.2.11 [alg.equal]:
>>>
>>>
>>>
>>> template<class InputIterator1, class InputIterator2>
>>> bool equal(InputIterator1 first1, InputIterator1 last1,
>>>            InputIterator2 first2);
>>>
>>> template<class InputIterator1, class InputIterator2, class
>>> BinaryPredicate>
>>> bool equal(InputIterator1 first1, InputIterator1 last1,
>>>            InputIterator2 first2, BinaryPredicate pred);
>>>
>>> template<class InputIterator1, class InputIterator2>
>>> bool equal(InputIterator1 first1, InputIterator1 last1,
>>>            InputIterator2 first2, InputIterator2 last2);
>>>
>>> template<class InputIterator1, class InputIterator2, class
>>> BinaryPredicate>
>>> bool equal(InputIterator1 first1, InputIterator1 last1,
>>>
>>>            InputIterator2 first2, InputIterator2 last2,
>>>            BinaryPredicate pred);
>>>
>>>
>>>
>>> Billy O'Neal
>>> https://github.com/BillyONeal/ <https://bitbucket.org/BillyONeal/>
>>> http://stackoverflow.com/users/82320/billy-oneal
>>> Malware Response Instructor - BleepingComputer.com
>>>
>>>
>>> On Wed, Sep 18, 2013 at 10:57 AM, <morw...@gmail.com> wrote:
>>>
>>>> @Nevin: I had a problem I could solve with std::transform but which
>>>> would have been more conveniently solved with a binary std::for_each.
>>>> Since std::transform only works with unary and binary functors, I
>>>> thought std::for_each could also have a useful binary overload, but did
>>>> not think it further. I didn't check, but there are probably several
>>>> other algorithms that could have a n-ary overload and don't have it. Also,
>>>> I kept the name std::for_each instead of choosing a new one since the
>>>> logic involved is pretty much the same :)
>>>>
>>>> @Billy: You're totally right about the two mistakes I made. I didn't
>>>> have my code at hand and hastily wrote this one while I should have
>>>> taken more time to avoid the errors. I don't know whether the parameter
>>>> last2 is useful though; std::transform does not have it for
>>>> example.
>>>>
>>>> --
>>>>
>>>> ---
>>>> You received this message because you are subscribed to the Google
>>>> Groups "ISO C++ Standard - Future Proposals" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to std-proposal...@isocpp.org.
>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>> Visit this group at
>>>> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>>>>
>>>
>>>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_216_13262601.1379536534306
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Not quite. The variadic pack has to come at the end of the=
 parameter list, so if you put the function first, then yeah that will work=
.. But it breaks with the traditional order of parameters in the STL. I thin=
k the best you can do to support a variadic for_each is to pass the begin i=
terators in as a tuple,and specify a last iterator to constrain the size of=
 the range, followed by the function. i.e.<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;=
&nbsp;&nbsp; template &lt;typename Iter, typename Func, typename... Iters&g=
t;<br>&nbsp;&nbsp;&nbsp; for_each(std::tuple&lt;Iter, Iters...&gt; firsts, =
Iter last, Func f);<br><br>On Wednesday, 18 September 2013 16:10:26 UTC-4, =
Bengt Gustafsson  wrote:<blockquote class=3D"gmail_quote" style=3D"margin: =
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div d=
ir=3D"ltr">Can't this be done for any arity using variadic templates:<div><=
br></div><div>template&lt;typename Function, typename InputIterator1, typen=
ame... InputIterators&gt; Function for_each(InputIterator1 first1, InputITe=
rator1 last1, InputIterators... firsts, Function f);</div><div><br></div><d=
iv>This will require a helper variadic function to increment all the first =
iterators, but that should not be a problem.</div><div><br></div><div>On th=
e other hand this does not go well with supplying all the end iterators unl=
ess we pass all the firsts and then all the lasts. Or can you put the ... l=
ike this to get pairs of iterator parameters, I'm uncertain ablout the comm=
a there:</div><div><br></div><div><div>template&lt;typename Function, typen=
ame... InputIterators&gt; Function for_each(InputIterators first1, InputITe=
rators last1..., Function f);</div><div><br></div><br>Den onsdagen den 18:e=
 september 2013 kl. 21:24:03 UTC+2 skrev Bryan St. Amour:<blockquote class=
=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc s=
olid;padding-left:1ex"><div dir=3D"ltr">Binary std::for_each is different t=
han the other non-mutating algorithms however, because as a precondition th=
ere should be at least as many elements in [first2, last2) than there are i=
n [first1, last1), just like std::transform. My personal opinion is that bi=
nary std::for_each should not take in last2 as a parameter.<br><br>On Wedne=
sday, 18 September 2013 15:17:04 UTC-4, Billy O'Neal  wrote:<blockquote cla=
ss=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc=
 solid;padding-left:1ex"><div dir=3D"ltr"><div><div><table cellpadding=3D"0=
"><tbody><tr><td><table cellpadding=3D"0"><tbody><tr><td><p>@morwenn29:</p>=
<p>&nbsp;</p><p>All the non-mutating algorithms accepting two ranges have v=
ariants accepting both iterators for the second range in N3691. (That is, m=
ismatch, find, is_permutation, and equal) Consider 25.2.11 [alg.equal]:</p>

<p>&nbsp;</p><p><font face=3D"courier new,monospace">template&lt;class Inpu=
tIterator1, class InputIterator2&gt;<br>bool equal(InputIterator1 first1, I=
nputIterator1 last1,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp; InputIterator2 first2);<br><br>template&lt;class InputIterator1, =
class InputIterator2, class BinaryPredicate&gt;<br>

bool equal(InputIterator1 first1, InputIterator1 last1,<br>&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InputIterator2 first2, BinaryP=
redicate pred);<br></font></p><p><font face=3D"courier new,monospace">templ=
ate&lt;class InputIterator1, class InputIterator2&gt;<br>

bool equal(InputIterator1 first1, InputIterator1 last1,<br>&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InputIterator2 first2, InputIt=
erator2 last2);<br></font></p><p><font face=3D"courier new,monospace">templ=
ate&lt;class InputIterator1, class InputIterator2, class BinaryPredicate&gt=
;<br>

bool equal(InputIterator1 first1, InputIterator1 last1,</font></p><p><font =
face=3D"courier new,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp; InputIterator2 first2, InputIterator2 last2,<br>&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BinaryPredicate pre=
d);</font></p><p>&nbsp;</p></td>
</tr>
</tbody></table></td></tr></tbody></table></div></div></div><div><br clear=
=3D"all"><div><div dir=3D"ltr"><div>Billy O'Neal</div><div><a href=3D"https=
://bitbucket.org/BillyONeal/" target=3D"_blank">https://github.com/BillyONe=
al/</a></div>

<div><a href=3D"http://stackoverflow.com/users/82320/billy-oneal" target=3D=
"_blank">http://stackoverflow.com/<wbr>users/82320/billy-oneal</a></div><di=
v>Malware Response Instructor - BleepingComputer.com</div></div></div>
<br><br><div class=3D"gmail_quote">On Wed, Sep 18, 2013 at 10:57 AM,  <span=
 dir=3D"ltr">&lt;<a>morw...@gmail.com</a>&gt;</span> wrote:<br><blockquote =
class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid=
;padding-left:1ex">

<div dir=3D"ltr">@Nevin: I had a problem I could solve with std::transform =
but which would have been more conveniently solved with a binary std::for_e=
ach.<br>Since std::transform only works with unary and binary functors, I t=
hought std::for_each could also have a useful binary overload, but did<br>

not think it further. I didn't check, but there are probably several other =
algorithms that could have a n-ary overload and don't have it. Also,<br>I k=
ept the name std::for_each instead of choosing a new one since the logic in=
volved is pretty much the same :)<br>

<br>@Billy: You're totally right about the two mistakes I made. I didn't ha=
ve my code at hand and hastily wrote this one while I should have<br>taken =
more time to avoid the errors. I don't know whether the parameter last2 is =
useful though; std::transform does not have it for<br>

example.<br></div><div><div>

<p></p>

-- <br>
&nbsp;<br>
--- <br>
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a>std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a>std-pr...@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/<wbr>isocpp.or=
g/group/std-<wbr>proposals/</a>.<br>
</div></div></blockquote></div><br></div>
</blockquote></div></blockquote></div></div></blockquote></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_216_13262601.1379536534306--

.


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Wed, 18 Sep 2013 13:38:59 -0700 (PDT)
Raw View
------=_Part_157_28174320.1379536739746
Content-Type: text/plain; charset=KOI8-R
Content-Transfer-Encoding: quoted-printable

I agree with the opinion that such an algorithm should have another name.

=D3=D2=C5=C4=C1, 18 =D3=C5=CE=D4=D1=C2=D2=D1 2013 =C7., 16:28:44 UTC+4 =D0=
=CF=CC=D8=DA=CF=D7=C1=D4=C5=CC=D8 morw...@gmail.com=20
=CE=C1=D0=C9=D3=C1=CC:

> I sometimes - often - want to apply binary functions element-wise between=
=20
> two ranges. In order to do so, it would be great to have
> an overload of std::for_each for binary functions. It would be something=
=20
> like this:
>
> template<class InputIt1, class InputIt2 class BinaryFunction>
> UnaryFunction for_each(InputIt1 first1, InputIt1 last1, InputIt2 first2, =
BinaryFunction f){
>     for (; first1 !=3D last1; ++first1, ++first2) {
>         f(*first1, *first2);
>     }
>     return f;}
>
>
>

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

------=_Part_157_28174320.1379536739746
Content-Type: text/html; charset=KOI8-R
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I agree with the opinion that such an algorithm shoul=
d have another name.</div><div><br>=D3=D2=C5=C4=C1, 18 =D3=C5=CE=D4=D1=C2=
=D2=D1 2013&nbsp;=C7., 16:28:44 UTC+4 =D0=CF=CC=D8=DA=CF=D7=C1=D4=C5=CC=D8 =
morw...@gmail.com =CE=C1=D0=C9=D3=C1=CC:</div><blockquote class=3D"gmail_qu=
ote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-col=
or: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;">=
<div dir=3D"ltr">I sometimes - often - want to apply binary functions eleme=
nt-wise between two ranges. In order to do so, it would be great to have<br=
>an overload of std::for_each for binary functions. It would be something l=
ike this:<br><br><div style=3D"text-align: left;" dir=3D"ltr"><div><pre><sp=
an>template</span><span>&lt;</span><span>class</span> InputIt1, class Input=
It2 <span>class</span> BinaryFunction<span>&gt;</span>
UnaryFunction for_each<span>(</span>InputIt1 first1, InputIt1 last1, InputI=
t2 first2, BinaryFunction f<span>)</span>
<span>{</span>
    <span>for</span> <span>(</span><span>;</span> first1 <span>!</span><spa=
n>=3D</span> last1<span>;</span> <span>++</span>first1, ++first2<span>)</sp=
an> <span>{</span>
        f<span>(</span><span>*</span>first<span>1, *first2)</span><span>;</=
span>
    <span>}</span>
    <span>return</span> f<span>;</span>
<span>}</span></pre></div></div><br></div></blockquote></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_157_28174320.1379536739746--

.


Author: Zhihao Yuan <zy@miator.net>
Date: Wed, 18 Sep 2013 17:00:49 -0400
Raw View
On Wed, Sep 18, 2013 at 4:38 PM, Vlad from Moscow <vlad.moscow@mail.ru> wrote:
> I agree with the opinion that such an algorithm should have another name.

Like std::for_both ?  LOL

Actually, I think we could have a zip iterator

  http://www.boost.org/doc/libs/1_54_0/libs/iterator/doc/zip_iterator.html

and even zip range adaptor to solve this.

We already have std::tuple, I don't see a blocker for zip iterator.

--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://4bsd.biz/

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@gmail.com>
Date: Wed, 18 Sep 2013 23:45:04 +0200
Raw View
2013/9/18 Zhihao Yuan <zy@miator.net>:
> Actually, I think we could have a zip iterator
>
>   http://www.boost.org/doc/libs/1_54_0/libs/iterator/doc/zip_iterator.html
>
> and even zip range adaptor to solve this.
>
> We already have std::tuple, I don't see a blocker for zip iterator.

The current "blocker" are the broken iterator requirements which have
the effect that zip-iterator cannot be anything than an InputIterator
;-) But don't take this comment too serious: Yes, we can standardize
zip iterator, but it would be of much more value, if we could fix the
iterator requirements also.

- Daniel

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: Magnus Fromreide <magfr@lysator.liu.se>
Date: Wed, 18 Sep 2013 23:48:55 +0200
Raw View
On Wed, 2013-09-18 at 13:35 -0700, Bryan St. Amour wrote:
> Not quite. The variadic pack has to come at the end of the parameter
> list, so if you put the function first, then yeah that will work. But
> it breaks with the traditional order of parameters in the STL. I think
> the best you can do to support a variadic for_each is to pass the
> begin iterators in as a tuple,and specify a last iterator to constrain
> the size of the range, followed by the function. i.e.
>
>     template <typename Iter, typename Func, typename... Iters>
>     for_each(std::tuple<Iter, Iters...> firsts, Iter last, Func f);

One could also embrace that necessity and use

template <typename Iter, typename Func, typename... Iters>
for_each(Iter first1, Iter last1, Func f, Iters .. firsts)

with the advantage that it covers the already present case with 0 Iters
as well. This also marks the trailing firsts as lesser than the initial
one so they are not to be expected to be used for range checking.

@ Billy:
I also think std::for_each and std::transform are equally mutating since
one can implement them in terms of each other.


From this follows that another overload for transform might be useful as
well:

template <class InputIterator, class OutputIterator, class Operation,
          class ... InputIterators>
OutputIterator
transform_n(InputIterator first, InputIterator last, OutputIterator result,
            Operation op, InputIterators ... firsts); (*)

If we have one of them then the other one ought to exist as well and as
we already have transform with an additional iterator that speaks in
favor of for_each with an additional iterator, but I think the
generalized versions from above are better.

/MF


(*) transform_n in order to avoid the clashing with
    transform(I1, I1, I2, O, B)

> On Wednesday, 18 September 2013 16:10:26 UTC-4, Bengt Gustafsson
> wrote:
>         Can't this be done for any arity using variadic templates:
>
>
>         template<typename Function, typename InputIterator1,
>         typename... InputIterators> Function for_each(InputIterator1
>         first1, InputITerator1 last1, InputIterators... firsts,
>         Function f);
>
>
>         This will require a helper variadic function to increment all
>         the first iterators, but that should not be a problem.
>
>
>         On the other hand this does not go well with supplying all the
>         end iterators unless we pass all the firsts and then all the
>         lasts. Or can you put the ... like this to get pairs of
>         iterator parameters, I'm uncertain ablout the comma there:
>
>
>         template<typename Function, typename... InputIterators>
>         Function for_each(InputIterators first1, InputITerators
>         last1..., Function f);
>
>
>
>         Den onsdagen den 18:e september 2013 kl. 21:24:03 UTC+2 skrev
>         Bryan St. Amour:
>                 Binary std::for_each is different than the other
>                 non-mutating algorithms however, because as a
>                 precondition there should be at least as many elements
>                 in [first2, last2) than there are in [first1, last1),
>                 just like std::transform. My personal opinion is that
>                 binary std::for_each should not take in last2 as a
>                 parameter.
>
>                 On Wednesday, 18 September 2013 15:17:04 UTC-4, Billy
>                 O'Neal wrote:
>                         @morwenn29:
>
>
>
>                         All the non-mutating algorithms accepting two
>                         ranges have variants accepting both iterators
>                         for the second range in N3691. (That is,
>                         mismatch, find, is_permutation, and equal)
>                         Consider 25.2.11 [alg.equal]:
>
>
>
>                         template<class InputIterator1, class
>                         InputIterator2>
>                         bool equal(InputIterator1 first1,
>                         InputIterator1 last1,
>                                    InputIterator2 first2);
>
>                         template<class InputIterator1, class
>                         InputIterator2, class BinaryPredicate>
>                         bool equal(InputIterator1 first1,
>                         InputIterator1 last1,
>                                    InputIterator2 first2,
>                         BinaryPredicate pred);
>
>
>                         template<class InputIterator1, class
>                         InputIterator2>
>                         bool equal(InputIterator1 first1,
>                         InputIterator1 last1,
>                                    InputIterator2 first2,
>                         InputIterator2 last2);
>
>
>                         template<class InputIterator1, class
>                         InputIterator2, class BinaryPredicate>
>                         bool equal(InputIterator1 first1,
>                         InputIterator1 last1,
>
>                                    InputIterator2 first2,
>                         InputIterator2 last2,
>                                    BinaryPredicate pred);
>
>
>
>
>
>                         Billy O'Neal
>                         https://github.com/BillyONeal/
>                         http://stackoverflow.com/users/82320/billy-oneal
>                         Malware Response Instructor -
>                         BleepingComputer.com
>
>
>                         On Wed, Sep 18, 2013 at 10:57 AM,
>                         <morw...@gmail.com> wrote:
>                                 @Nevin: I had a problem I could solve
>                                 with std::transform but which would
>                                 have been more conveniently solved
>                                 with a binary std::for_each.
>                                 Since std::transform only works with
>                                 unary and binary functors, I thought
>                                 std::for_each could also have a useful
>                                 binary overload, but did
>                                 not think it further. I didn't check,
>                                 but there are probably several other
>                                 algorithms that could have a n-ary
>                                 overload and don't have it. Also,
>                                 I kept the name std::for_each instead
>                                 of choosing a new one since the logic
>                                 involved is pretty much the same :)
>
>                                 @Billy: You're totally right about the
>                                 two mistakes I made. I didn't have my
>                                 code at hand and hastily wrote this
>                                 one while I should have
>                                 taken more time to avoid the errors. I
>                                 don't know whether the parameter last2
>                                 is useful though; std::transform does
>                                 not have it for
>                                 example.
>
>
>
>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: "Billy O'Neal" <billy.oneal@gmail.com>
Date: Wed, 18 Sep 2013 14:56:25 -0700
Raw View
--089e01634ec29fadc704e6af84fe
Content-Type: text/plain; charset=ISO-8859-1

>I also think std::for_each and std::transform are equally mutating since
one can implement them in terms of each other.

No, they can't. They can in the restricted case that the output iterator
and the first input iterator to transform are the same.

As for "mutating" -- I didn't name them that way. That's what What the
Standard Says^TM.

Billy O'Neal
https://github.com/BillyONeal/ <https://bitbucket.org/BillyONeal/>
http://stackoverflow.com/users/82320/billy-oneal
Malware Response Instructor - BleepingComputer.com


On Wed, Sep 18, 2013 at 2:48 PM, Magnus Fromreide <magfr@lysator.liu.se>wrote:

> On Wed, 2013-09-18 at 13:35 -0700, Bryan St. Amour wrote:
> > Not quite. The variadic pack has to come at the end of the parameter
> > list, so if you put the function first, then yeah that will work. But
> > it breaks with the traditional order of parameters in the STL. I think
> > the best you can do to support a variadic for_each is to pass the
> > begin iterators in as a tuple,and specify a last iterator to constrain
> > the size of the range, followed by the function. i.e.
> >
> >     template <typename Iter, typename Func, typename... Iters>
> >     for_each(std::tuple<Iter, Iters...> firsts, Iter last, Func f);
>
> One could also embrace that necessity and use
>
> template <typename Iter, typename Func, typename... Iters>
> for_each(Iter first1, Iter last1, Func f, Iters .. firsts)
>
> with the advantage that it covers the already present case with 0 Iters
> as well. This also marks the trailing firsts as lesser than the initial
> one so they are not to be expected to be used for range checking.
>
> @ Billy:
> I also think std::for_each and std::transform are equally mutating since
> one can implement them in terms of each other.
>
>
> From this follows that another overload for transform might be useful as
> well:
>
> template <class InputIterator, class OutputIterator, class Operation,
>           class ... InputIterators>
> OutputIterator
> transform_n(InputIterator first, InputIterator last, OutputIterator result,
>             Operation op, InputIterators ... firsts); (*)
>
> If we have one of them then the other one ought to exist as well and as
> we already have transform with an additional iterator that speaks in
> favor of for_each with an additional iterator, but I think the
> generalized versions from above are better.
>
> /MF
>
>
> (*) transform_n in order to avoid the clashing with
>     transform(I1, I1, I2, O, B)
>
> > On Wednesday, 18 September 2013 16:10:26 UTC-4, Bengt Gustafsson
> > wrote:
> >         Can't this be done for any arity using variadic templates:
> >
> >
> >         template<typename Function, typename InputIterator1,
> >         typename... InputIterators> Function for_each(InputIterator1
> >         first1, InputITerator1 last1, InputIterators... firsts,
> >         Function f);
> >
> >
> >         This will require a helper variadic function to increment all
> >         the first iterators, but that should not be a problem.
> >
> >
> >         On the other hand this does not go well with supplying all the
> >         end iterators unless we pass all the firsts and then all the
> >         lasts. Or can you put the ... like this to get pairs of
> >         iterator parameters, I'm uncertain ablout the comma there:
> >
> >
> >         template<typename Function, typename... InputIterators>
> >         Function for_each(InputIterators first1, InputITerators
> >         last1..., Function f);
> >
> >
> >
> >         Den onsdagen den 18:e september 2013 kl. 21:24:03 UTC+2 skrev
> >         Bryan St. Amour:
> >                 Binary std::for_each is different than the other
> >                 non-mutating algorithms however, because as a
> >                 precondition there should be at least as many elements
> >                 in [first2, last2) than there are in [first1, last1),
> >                 just like std::transform. My personal opinion is that
> >                 binary std::for_each should not take in last2 as a
> >                 parameter.
> >
> >                 On Wednesday, 18 September 2013 15:17:04 UTC-4, Billy
> >                 O'Neal wrote:
> >                         @morwenn29:
> >
> >
> >
> >                         All the non-mutating algorithms accepting two
> >                         ranges have variants accepting both iterators
> >                         for the second range in N3691. (That is,
> >                         mismatch, find, is_permutation, and equal)
> >                         Consider 25.2.11 [alg.equal]:
> >
> >
> >
> >                         template<class InputIterator1, class
> >                         InputIterator2>
> >                         bool equal(InputIterator1 first1,
> >                         InputIterator1 last1,
> >                                    InputIterator2 first2);
> >
> >                         template<class InputIterator1, class
> >                         InputIterator2, class BinaryPredicate>
> >                         bool equal(InputIterator1 first1,
> >                         InputIterator1 last1,
> >                                    InputIterator2 first2,
> >                         BinaryPredicate pred);
> >
> >
> >                         template<class InputIterator1, class
> >                         InputIterator2>
> >                         bool equal(InputIterator1 first1,
> >                         InputIterator1 last1,
> >                                    InputIterator2 first2,
> >                         InputIterator2 last2);
> >
> >
> >                         template<class InputIterator1, class
> >                         InputIterator2, class BinaryPredicate>
> >                         bool equal(InputIterator1 first1,
> >                         InputIterator1 last1,
> >
> >                                    InputIterator2 first2,
> >                         InputIterator2 last2,
> >                                    BinaryPredicate pred);
> >
> >
> >
> >
> >
> >                         Billy O'Neal
> >                         https://github.com/BillyONeal/
> >                         http://stackoverflow.com/users/82320/billy-oneal
> >                         Malware Response Instructor -
> >                         BleepingComputer.com
> >
> >
> >                         On Wed, Sep 18, 2013 at 10:57 AM,
> >                         <morw...@gmail.com> wrote:
> >                                 @Nevin: I had a problem I could solve
> >                                 with std::transform but which would
> >                                 have been more conveniently solved
> >                                 with a binary std::for_each.
> >                                 Since std::transform only works with
> >                                 unary and binary functors, I thought
> >                                 std::for_each could also have a useful
> >                                 binary overload, but did
> >                                 not think it further. I didn't check,
> >                                 but there are probably several other
> >                                 algorithms that could have a n-ary
> >                                 overload and don't have it. Also,
> >                                 I kept the name std::for_each instead
> >                                 of choosing a new one since the logic
> >                                 involved is pretty much the same :)
> >
> >                                 @Billy: You're totally right about the
> >                                 two mistakes I made. I didn't have my
> >                                 code at hand and hastily wrote this
> >                                 one while I should have
> >                                 taken more time to avoid the errors. I
> >                                 don't know whether the parameter last2
> >                                 is useful though; std::transform does
> >                                 not have it for
> >                                 example.
> >
> >
> >
> >
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--089e01634ec29fadc704e6af84fe
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>&gt;I also think std::for_each and std::transform are=
 equally mutating since<br> one can implement them in terms of each other.<=
/div><div>=A0</div><div>No, they can&#39;t. They can in the restricted case=
 that the output iterator and the first input iterator to transform are the=
 same.</div>

<div>=A0</div><div>As for &quot;mutating&quot; -- I didn&#39;t name them th=
at way. That&#39;s what What the Standard Says^TM.</div></div><div class=3D=
"gmail_extra"><br clear=3D"all"><div><div dir=3D"ltr"><div>Billy O&#39;Neal=
</div>

<div><a href=3D"https://bitbucket.org/BillyONeal/" target=3D"_blank">https:=
//github.com/BillyONeal/</a></div><div><a href=3D"http://stackoverflow.com/=
users/82320/billy-oneal" target=3D"_blank">http://stackoverflow.com/users/8=
2320/billy-oneal</a></div>

<div>Malware Response Instructor - BleepingComputer.com</div></div></div>
<br><br><div class=3D"gmail_quote">On Wed, Sep 18, 2013 at 2:48 PM, Magnus =
Fromreide <span dir=3D"ltr">&lt;<a href=3D"mailto:magfr@lysator.liu.se" tar=
get=3D"_blank">magfr@lysator.liu.se</a>&gt;</span> wrote:<br><blockquote cl=
ass=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;p=
adding-left:1ex">

On Wed, 2013-09-18 at 13:35 -0700, Bryan St. Amour wrote:<br>
&gt; Not quite. The variadic pack has to come at the end of the parameter<b=
r>
&gt; list, so if you put the function first, then yeah that will work. But<=
br>
&gt; it breaks with the traditional order of parameters in the STL. I think=
<br>
&gt; the best you can do to support a variadic for_each is to pass the<br>
&gt; begin iterators in as a tuple,and specify a last iterator to constrain=
<br>
&gt; the size of the range, followed by the function. i.e.<br>
&gt;<br>
&gt; =A0 =A0 template &lt;typename Iter, typename Func, typename... Iters&g=
t;<br>
&gt; =A0 =A0 for_each(std::tuple&lt;Iter, Iters...&gt; firsts, Iter last, F=
unc f);<br>
<br>
One could also embrace that necessity and use<br>
<br>
template &lt;typename Iter, typename Func, typename... Iters&gt;<br>
for_each(Iter first1, Iter last1, Func f, Iters .. firsts)<br>
<br>
with the advantage that it covers the already present case with 0 Iters<br>
as well. This also marks the trailing firsts as lesser than the initial<br>
one so they are not to be expected to be used for range checking.<br>
<br>
@ Billy:<br>
I also think std::for_each and std::transform are equally mutating since<br=
>
one can implement them in terms of each other.<br>
<br>
<br>
From this follows that another overload for transform might be useful as<br=
>
well:<br>
<br>
template &lt;class InputIterator, class OutputIterator, class Operation,<br=
>
=A0 =A0 =A0 =A0 =A0 class ... InputIterators&gt;<br>
OutputIterator<br>
transform_n(InputIterator first, InputIterator last, OutputIterator result,=
<br>
=A0 =A0 =A0 =A0 =A0 =A0 Operation op, InputIterators ... firsts); (*)<br>
<br>
If we have one of them then the other one ought to exist as well and as<br>
we already have transform with an additional iterator that speaks in<br>
favor of for_each with an additional iterator, but I think the<br>
generalized versions from above are better.<br>
<br>
/MF<br>
<br>
<br>
(*) transform_n in order to avoid the clashing with<br>
=A0 =A0 transform(I1, I1, I2, O, B)<br>
<br>
&gt; On Wednesday, 18 September 2013 16:10:26 UTC-4, Bengt Gustafsson<br>
&gt; wrote:<br>
&gt; =A0 =A0 =A0 =A0 Can&#39;t this be done for any arity using variadic te=
mplates:<br>
&gt;<br>
&gt;<br>
&gt; =A0 =A0 =A0 =A0 template&lt;typename Function, typename InputIterator1=
,<br>
&gt; =A0 =A0 =A0 =A0 typename... InputIterators&gt; Function for_each(Input=
Iterator1<br>
&gt; =A0 =A0 =A0 =A0 first1, InputITerator1 last1, InputIterators... firsts=
,<br>
&gt; =A0 =A0 =A0 =A0 Function f);<br>
&gt;<br>
&gt;<br>
&gt; =A0 =A0 =A0 =A0 This will require a helper variadic function to increm=
ent all<br>
&gt; =A0 =A0 =A0 =A0 the first iterators, but that should not be a problem.=
<br>
&gt;<br>
&gt;<br>
&gt; =A0 =A0 =A0 =A0 On the other hand this does not go well with supplying=
 all the<br>
&gt; =A0 =A0 =A0 =A0 end iterators unless we pass all the firsts and then a=
ll the<br>
&gt; =A0 =A0 =A0 =A0 lasts. Or can you put the ... like this to get pairs o=
f<br>
&gt; =A0 =A0 =A0 =A0 iterator parameters, I&#39;m uncertain ablout the comm=
a there:<br>
&gt;<br>
&gt;<br>
&gt; =A0 =A0 =A0 =A0 template&lt;typename Function, typename... InputIterat=
ors&gt;<br>
&gt; =A0 =A0 =A0 =A0 Function for_each(InputIterators first1, InputITerator=
s<br>
&gt; =A0 =A0 =A0 =A0 last1..., Function f);<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; =A0 =A0 =A0 =A0 Den onsdagen den 18:e september 2013 kl. 21:24:03 UTC+=
2 skrev<br>
&gt; =A0 =A0 =A0 =A0 Bryan St. Amour:<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Binary std::for_each is different than=
 the other<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 non-mutating algorithms however, becau=
se as a<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 precondition there should be at least =
as many elements<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 in [first2, last2) than there are in [=
first1, last1),<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 just like std::transform. My personal =
opinion is that<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 binary std::for_each should not take i=
n last2 as a<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 parameter.<br>
&gt;<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 On Wednesday, 18 September 2013 15:17:=
04 UTC-4, Billy<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 O&#39;Neal wrote:<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 @morwenn29:<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 All the non-mutating a=
lgorithms accepting two<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ranges have variants a=
ccepting both iterators<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 for the second range i=
n N3691. (That is,<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mismatch, find, is_per=
mutation, and equal)<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Consider 25.2.11 [alg.=
equal]:<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 template&lt;class Inpu=
tIterator1, class<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 InputIterator2&gt;<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 bool equal(InputIterat=
or1 first1,<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 InputIterator1 last1,<=
br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0InputIterator2 first2);<br>
&gt;<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 template&lt;class Inpu=
tIterator1, class<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 InputIterator2, class =
BinaryPredicate&gt;<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 bool equal(InputIterat=
or1 first1,<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 InputIterator1 last1,<=
br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0InputIterator2 first2,<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 BinaryPredicate pred);=
<br>
&gt;<br>
&gt;<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 template&lt;class Inpu=
tIterator1, class<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 InputIterator2&gt;<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 bool equal(InputIterat=
or1 first1,<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 InputIterator1 last1,<=
br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0InputIterator2 first2,<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 InputIterator2 last2);=
<br>
&gt;<br>
&gt;<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 template&lt;class Inpu=
tIterator1, class<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 InputIterator2, class =
BinaryPredicate&gt;<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 bool equal(InputIterat=
or1 first1,<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 InputIterator1 last1,<=
br>
&gt;<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0InputIterator2 first2,<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 InputIterator2 last2,<=
br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0BinaryPredicate pred);<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Billy O&#39;Neal<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <a href=3D"https://git=
hub.com/BillyONeal/" target=3D"_blank">https://github.com/BillyONeal/</a><b=
r>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <a href=3D"http://stac=
koverflow.com/users/82320/billy-oneal" target=3D"_blank">http://stackoverfl=
ow.com/users/82320/billy-oneal</a><br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Malware Response Instr=
uctor -<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 BleepingComputer.com<b=
r>
&gt;<br>
&gt;<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 On Wed, Sep 18, 2013 a=
t 10:57 AM,<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 &lt;<a href=3D"mailto:=
morw...@gmail.com">morw...@gmail.com</a>&gt; wrote:<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 @Nevin=
: I had a problem I could solve<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 with s=
td::transform but which would<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 have b=
een more conveniently solved<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 with a=
 binary std::for_each.<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Since =
std::transform only works with<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unary =
and binary functors, I thought<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 std::f=
or_each could also have a useful<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 binary=
 overload, but did<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 not th=
ink it further. I didn&#39;t check,<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 but th=
ere are probably several other<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 algori=
thms that could have a n-ary<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 overlo=
ad and don&#39;t have it. Also,<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 I kept=
 the name std::for_each instead<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 of cho=
osing a new one since the logic<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 involv=
ed is pretty much the same :)<br>
&gt;<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 @Billy=
: You&#39;re totally right about the<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 two mi=
stakes I made. I didn&#39;t have my<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 code a=
t hand and hastily wrote this<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 one wh=
ile I should have<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 taken =
more time to avoid the errors. I<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 don&#3=
9;t know whether the parameter last2<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 is use=
ful though; std::transform does<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 not ha=
ve it for<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 exampl=
e.<br>
<div class=3D"HOEnZb"><div class=3D"h5">&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
<br>
--<br>
<br>
---<br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org">std-propo=
sals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></blockquote></div><br></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--089e01634ec29fadc704e6af84fe--

.


Author: Magnus Fromreide <magfr@lysator.liu.se>
Date: Thu, 19 Sep 2013 00:43:59 +0200
Raw View
On Wed, 2013-09-18 at 14:56 -0700, Billy O'Neal wrote:
> >I also think std::for_each and std::transform are equally mutating
> since
> one can implement them in terms of each other.
>
> No, they can't. They can in the restricted case that the output
> iterator and the first input iterator to transform are the same.

They can, but it ain't simple, nor beautiful.



transform using for_each:

template <class OutputIterator, class UnaryOperation>
struct helper {
  helper(OutputIterator o_, UnaryOperation u_) : o(o_), u(u_) { }
  template <class T> void operator()(T t) { *o++ = u(t); }
  OutputIterator res() { return o; }
private:
  OutputIterator o;
  UnaryOperation u;
};

template <class InputIterator, class OutputIterator,
          class UnaryOperation>
OutputIterator
transform(InputIterator first, InputIterator last,
          OutputIterator result, UnaryOperation op)
{
    return std::for_each(first, last,
        helper<OutputIterator, UnaryOperation>(result, op)).res();
}



for_each using transform:

template <class Function>
struct helper {
  typedef std::output_iterator_tag iterator_category;
  typedef long difference_type;
  typedef void pointer, reference;
  struct value_type {
    value_type(Function& f_) : f(f_) { }
    template <class T> void operator=(T t) { f(t); }
  private:
    Function& f;
  };
  helper(Function f_) : f(f_) { }
  helper& operator++() { return *this; }
  value_type operator*() { return value_type(f); }
  Function res() { return f; }
private:
  Function f;
};

struct identity {
  template <class T> T operator()(T t) const { return t; }
};

template <class InputIterator, class Function>
Function for_each(InputIterator first, InputIterator last, Function f)
{
    return std::transform(first, last, helper<Function>(f), identity()).res();
}


I admit to not having tested the above two pieces of code as much as
would be needed if I were to use it but as thought food it should be
enough.

> As for "mutating" -- I didn't name them that way. That's what What the
> Standard Says^TM.

:-)

/MF


--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: "Billy O'Neal" <billy.oneal@gmail.com>
Date: Wed, 18 Sep 2013 15:47:49 -0700
Raw View
--089e01228b1477039c04e6b03c22
Content-Type: text/plain; charset=ISO-8859-1

I stand corrected :)

Billy O'Neal
https://github.com/BillyONeal/ <https://bitbucket.org/BillyONeal/>
http://stackoverflow.com/users/82320/billy-oneal
Malware Response Instructor - BleepingComputer.com


On Wed, Sep 18, 2013 at 3:43 PM, Magnus Fromreide <magfr@lysator.liu.se>wrote:

> On Wed, 2013-09-18 at 14:56 -0700, Billy O'Neal wrote:
> > >I also think std::for_each and std::transform are equally mutating
> > since
> > one can implement them in terms of each other.
> >
> > No, they can't. They can in the restricted case that the output
> > iterator and the first input iterator to transform are the same.
>
> They can, but it ain't simple, nor beautiful.
>
>
>
> transform using for_each:
>
> template <class OutputIterator, class UnaryOperation>
> struct helper {
>   helper(OutputIterator o_, UnaryOperation u_) : o(o_), u(u_) { }
>   template <class T> void operator()(T t) { *o++ = u(t); }
>   OutputIterator res() { return o; }
> private:
>   OutputIterator o;
>   UnaryOperation u;
> };
>
> template <class InputIterator, class OutputIterator,
>           class UnaryOperation>
> OutputIterator
> transform(InputIterator first, InputIterator last,
>           OutputIterator result, UnaryOperation op)
> {
>     return std::for_each(first, last,
>         helper<OutputIterator, UnaryOperation>(result, op)).res();
> }
>
>
>
> for_each using transform:
>
> template <class Function>
> struct helper {
>   typedef std::output_iterator_tag iterator_category;
>   typedef long difference_type;
>   typedef void pointer, reference;
>   struct value_type {
>     value_type(Function& f_) : f(f_) { }
>     template <class T> void operator=(T t) { f(t); }
>   private:
>     Function& f;
>   };
>   helper(Function f_) : f(f_) { }
>   helper& operator++() { return *this; }
>   value_type operator*() { return value_type(f); }
>   Function res() { return f; }
> private:
>   Function f;
> };
>
> struct identity {
>   template <class T> T operator()(T t) const { return t; }
> };
>
> template <class InputIterator, class Function>
> Function for_each(InputIterator first, InputIterator last, Function f)
> {
>     return std::transform(first, last, helper<Function>(f),
> identity()).res();
> }
>
>
> I admit to not having tested the above two pieces of code as much as
> would be needed if I were to use it but as thought food it should be
> enough.
>
> > As for "mutating" -- I didn't name them that way. That's what What the
> > Standard Says^TM.
>
> :-)
>
> /MF
>
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--089e01228b1477039c04e6b03c22
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I stand corrected :)</div><div class=3D"gmail_extra"><br c=
lear=3D"all"><div><div dir=3D"ltr"><div>Billy O&#39;Neal</div><div><a href=
=3D"https://bitbucket.org/BillyONeal/" target=3D"_blank">https://github.com=
/BillyONeal/</a></div>

<div><a href=3D"http://stackoverflow.com/users/82320/billy-oneal" target=3D=
"_blank">http://stackoverflow.com/users/82320/billy-oneal</a></div><div>Mal=
ware Response Instructor - BleepingComputer.com</div></div></div>
<br><br><div class=3D"gmail_quote">On Wed, Sep 18, 2013 at 3:43 PM, Magnus =
Fromreide <span dir=3D"ltr">&lt;<a href=3D"mailto:magfr@lysator.liu.se" tar=
get=3D"_blank">magfr@lysator.liu.se</a>&gt;</span> wrote:<br><blockquote cl=
ass=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;p=
adding-left:1ex">

<div class=3D"im">On Wed, 2013-09-18 at 14:56 -0700, Billy O&#39;Neal wrote=
:<br>
&gt; &gt;I also think std::for_each and std::transform are equally mutating=
<br>
&gt; since<br>
&gt; one can implement them in terms of each other.<br>
&gt;<br>
&gt; No, they can&#39;t. They can in the restricted case that the output<br=
>
&gt; iterator and the first input iterator to transform are the same.<br>
<br>
</div>They can, but it ain&#39;t simple, nor beautiful.<br>
<br>
<br>
<br>
transform using for_each:<br>
<br>
template &lt;class OutputIterator, class UnaryOperation&gt;<br>
struct helper {<br>
=A0 helper(OutputIterator o_, UnaryOperation u_) : o(o_), u(u_) { }<br>
=A0 template &lt;class T&gt; void operator()(T t) { *o++ =3D u(t); }<br>
=A0 OutputIterator res() { return o; }<br>
private:<br>
=A0 OutputIterator o;<br>
=A0 UnaryOperation u;<br>
<div class=3D"im">};<br>
<br>
template &lt;class InputIterator, class OutputIterator,<br>
</div>=A0 =A0 =A0 =A0 =A0 class UnaryOperation&gt;<br>
OutputIterator<br>
transform(InputIterator first, InputIterator last,<br>
=A0 =A0 =A0 =A0 =A0 OutputIterator result, UnaryOperation op)<br>
{<br>
=A0 =A0 return std::for_each(first, last,<br>
=A0 =A0 =A0 =A0 helper&lt;OutputIterator, UnaryOperation&gt;(result, op)).r=
es();<br>
}<br>
<br>
<br>
<br>
for_each using transform:<br>
<br>
template &lt;class Function&gt;<br>
struct helper {<br>
=A0 typedef std::output_iterator_tag iterator_category;<br>
=A0 typedef long difference_type;<br>
=A0 typedef void pointer, reference;<br>
=A0 struct value_type {<br>
=A0 =A0 value_type(Function&amp; f_) : f(f_) { }<br>
=A0 =A0 template &lt;class T&gt; void operator=3D(T t) { f(t); }<br>
=A0 private:<br>
=A0 =A0 Function&amp; f;<br>
=A0 };<br>
=A0 helper(Function f_) : f(f_) { }<br>
=A0 helper&amp; operator++() { return *this; }<br>
=A0 value_type operator*() { return value_type(f); }<br>
=A0 Function res() { return f; }<br>
private:<br>
=A0 Function f;<br>
};<br>
<br>
struct identity {<br>
=A0 template &lt;class T&gt; T operator()(T t) const { return t; }<br>
};<br>
<br>
template &lt;class InputIterator, class Function&gt;<br>
Function for_each(InputIterator first, InputIterator last, Function f)<br>
{<br>
=A0 =A0 return std::transform(first, last, helper&lt;Function&gt;(f), ident=
ity()).res();<br>
}<br>
<br>
<br>
I admit to not having tested the above two pieces of code as much as<br>
would be needed if I were to use it but as thought food it should be<br>
enough.<br>
<div class=3D"im"><br>
&gt; As for &quot;mutating&quot; -- I didn&#39;t name them that way. That&#=
39;s what What the<br>
&gt; Standard Says^TM.<br>
<br>
</div>:-)<br>
<span class=3D"HOEnZb"><font color=3D"#888888"><br>
/MF<br>
</font></span><div class=3D"HOEnZb"><div class=3D"h5"><br>
<br>
--<br>
<br>
---<br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org">std-propo=
sals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></blockquote></div><br></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--089e01228b1477039c04e6b03c22--

.


Author: Zhihao Yuan <zy@miator.net>
Date: Wed, 18 Sep 2013 19:19:43 -0400
Raw View
--047d7b34346422acff04e6b0accb
Content-Type: text/plain; charset=ISO-8859-1

On Sep 18, 2013 7:07 PM, "Zhihao Yuan" <zy@miator.net> wrote:
> So that InputIterator requires decltype, ForwardIterator and
> follow ups require iterator_traits<X>::reference.
>
> But of course this breaks user code...

Errr, not really; it just takes some time to adapt to, like std::addressof.

Do you think this is something can be changed with a library issue?

--
Zhihao

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--047d7b34346422acff04e6b0accb
Content-Type: text/html; charset=ISO-8859-1

<p>On Sep 18, 2013 7:07 PM, &quot;Zhihao Yuan&quot; &lt;<a href="mailto:zy@miator.net">zy@miator.net</a>&gt; wrote:<br>
&gt; So that InputIterator requires decltype, ForwardIterator and<br>
&gt; follow ups require iterator_traits&lt;X&gt;::reference.<br>
&gt;<br>
&gt; But of course this breaks user code...</p>
<p>Errr, not really; it just takes some time to adapt to, like std::addressof.</p>
<p>Do you think this is something can be changed with a library issue?</p>
<p>--<br>
Zhihao</p>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br />

--047d7b34346422acff04e6b0accb--

.


Author: Zhihao Yuan <zy@miator.net>
Date: Wed, 18 Sep 2013 19:07:14 -0400
Raw View
On Wed, Sep 18, 2013 at 5:45 PM, Daniel Kr=FCgler
<daniel.kruegler@gmail.com> wrote:
> The current "blocker" are the broken iterator requirements which have
> the effect that zip-iterator cannot be anything than an InputIterator
> ;-) But don't take this comment too serious: Yes, we can standardize
> zip iterator, but it would be of much more value, if we could fix the
> iterator requirements also.

Ah ha ha ha, yea.  There are always something in C++ which
has been "fixed" in many people's mind but is still physically broken...

The change in my mind (I roughly looked around in the standard
and saw no places being affected) is to simply remove the 3rd
bullet from 24.2.5/1:

  -- if X is a mutable iterator, reference is a reference to T; if X is
     a const iterator, reference is a reference to const T,

So that InputIterator requires decltype, ForwardIterator and
follow ups require iterator_traits<X>::reference.

But of course this breaks user code...

--=20
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://4bsd.biz/

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

.


Author: Marc <marc.glisse@gmail.com>
Date: Wed, 18 Sep 2013 20:36:12 -0700 (PDT)
Raw View
------=_Part_296_4562039.1379561772216
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Le mercredi 18 septembre 2013 23:48:55 UTC+2, Magnus Fromreide a =E9crit :
>
> On Wed, 2013-09-18 at 13:35 -0700, Bryan St. Amour wrote:=20
> > Not quite. The variadic pack has to come at the end of the parameter=20
> > list, so if you put the function first, then yeah that will work. But=
=20
> > it breaks with the traditional order of parameters in the STL. I think=
=20
> > the best you can do to support a variadic for_each is to pass the=20
> > begin iterators in as a tuple,and specify a last iterator to constrain=
=20
> > the size of the range, followed by the function. i.e.=20
> >    =20
> >     template <typename Iter, typename Func, typename... Iters>=20
> >     for_each(std::tuple<Iter, Iters...> firsts, Iter last, Func f);=20
>
> One could also embrace that necessity and use=20
>
> template <typename Iter, typename Func, typename... Iters>=20
> for_each(Iter first1, Iter last1, Func f, Iters .. firsts)=20
>
> with the advantage that it covers the already present case with 0 Iters=
=20
> as well. This also marks the trailing firsts as lesser than the initial=
=20
> one so they are not to be expected to be used for range checking.=20
>

Note that this is equivalent to:
template <typename Iter, typename...Args>
typename First<Args...>::type for_each(Iter first1, Iter last1,=20
Args...args);
Whether you decide now that f is the first or the last element of args...=
=20
doesn't change much.

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

------=_Part_296_4562039.1379561772216
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Le mercredi 18 septembre 2013 23:48:55 UTC+2, Magnus Fromr=
eide a =E9crit&nbsp;:<blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On Wed, 2=
013-09-18 at 13:35 -0700, Bryan St. Amour wrote:
<br>&gt; Not quite. The variadic pack has to come at the end of the paramet=
er
<br>&gt; list, so if you put the function first, then yeah that will work. =
But
<br>&gt; it breaks with the traditional order of parameters in the STL. I t=
hink
<br>&gt; the best you can do to support a variadic for_each is to pass the
<br>&gt; begin iterators in as a tuple,and specify a last iterator to const=
rain
<br>&gt; the size of the range, followed by the function. i.e.
<br>&gt; &nbsp; &nbsp;=20
<br>&gt; &nbsp; &nbsp; template &lt;typename Iter, typename Func, typename.=
... Iters&gt;
<br>&gt; &nbsp; &nbsp; for_each(std::tuple&lt;Iter, Iters...&gt; firsts, It=
er last, Func f);
<br>
<br>One could also embrace that necessity and use
<br>
<br>template &lt;typename Iter, typename Func, typename... Iters&gt;
<br>for_each(Iter first1, Iter last1, Func f, Iters .. firsts)
<br>
<br>with the advantage that it covers the already present case with 0 Iters
<br>as well. This also marks the trailing firsts as lesser than the initial
<br>one so they are not to be expected to be used for range checking.
<br></blockquote><div><br>Note that this is equivalent to:<br>template &lt;=
typename Iter, typename...Args&gt;<br>typename First&lt;Args...&gt;::type f=
or_each(Iter first1, Iter last1, Args...args);<br>Whether you decide now th=
at f is the first or the last element of args... doesn't change much.<br></=
div></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_296_4562039.1379561772216--

.


Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@gmail.com>
Date: Sun, 22 Sep 2013 19:53:05 +0200
Raw View
2013/9/19 Zhihao Yuan <zy@miator.net>:
> The change in my mind (I roughly looked around in the standard
> and saw no places being affected) is to simply remove the 3rd
> bullet from 24.2.5/1:
>
>   -- if X is a mutable iterator, reference is a reference to T; if X is
>      a const iterator, reference is a reference to const T,

I'm pretty sure we shouldn't remove that requirement, because this
wording is really required to exist when we look at the standard as a
whole thing. My personal suggestion would be to introduce new
requirement sets that better separate traversal and access
requirements, such as ForwardTraversalIterator requirements.

> So that InputIterator requires decltype, ForwardIterator and
> follow ups require iterator_traits<X>::reference.

I don't understand this conclusion and I see no evidence for it. Note
that Table 106 already clarifies that the return type of the
expression "*r" is "reference" (in code font) and 24.2.1 p11 says that
this means "iterator_traits<X>::reference". And 24.4.1 p1 emphasizes
that iterator_traits<X>::reference has to be defined for input
iterators.

> But of course this breaks user code...

It would break user-code and the library.

- Daniel

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.