What are your proposed semantics for the new functions?
Thanks,
Stefanus
So, if I write something like:
std::array<int> a = {0, 1, 2, 3, 4};
std::transform_if(begin(a), end(a), std::ostream_iterator(std::cout, “ “), [](int i) -> bool { return i % 2 == 0; }, [](int i) -> int { return i * 2; })
Should the output be “0 1 4 3 8 ” or “0 4 8 ”?
(Please forgive any typos in the code, I did not try to compile it)
Thanks,
Stefanus
From: vlad....@mail.ru [mailto:vlad....@mail.ru]
Sent: Tuesday, June 05, 2012 5:57 PM
To: std-pr...@isocpp.org
Thanks, that makes it very clear (“0 4 8 “ would be my expectation below).
I think this would be a perfectly fine addition. Are there other algorithms where we are missing an _if version?
Stefanus
--
Stefanus Du Toit stefanus...@intel.com
Intel Dynamic Mobility and Parallelism
Intel Waterloo
phone: +1 519 772 2576
Thanks, that makes it very clear (“0 4 8 “ would be my expectation below).
I think this would be a perfectly fine addition. Are there other algorithms where we are missing an _if version?
Stefanus
--
Stefanus Du Toit stefanus...@intel.com
Intel Dynamic Mobility and Parallelism
Intel Waterloo
phone: +1 519 772 2576
From: Vlad from Moscow [mailto:Vlad from Moscow]
I can suggest for example a who;e family of for_each algorithm.for_each_if;for_first;for_first_if;for_n;for_n_if;
I think using for_each_if makes the symantic of code more clear. The function can be very compound moreover it can be a member of a class and to write a wrapper for it that to include a condition inside its body is not a very good idea. The function can be universal while conditions can be changed. So I think the function and the condition should be separated in for_each family of algorithms.Let assume that we have some very compound function and want to apply it to some elements of a sequense which are equal to zero. Then we could writefor_each_if( s.begin(), s.end(), std::bind2nd( std::equal_to<T>(), 0 ), f );This code is more clear thanstd::for_each( s.begin(), s.end(), SomeWrapperWithUnclearAction );;And if the condition will be changed thenstd::for_each( s.begin(), s.end(), AnotherWrapperWithUnclearAction );;
endOn 6 June 2012 13:07, <vlad....@mail.ru> wrote:
There is one problem with the codefor_each(begin(s), end(s), [&](decltype(*end(s)) t) { if (v == 0) f(v); });What does for_each return? I would like to get f without the condition. Separating the condition and the operation allows to return the operation and use it in another algorithm.
Also I would llike that algorithms for_first and for_first_if would be taken into acccount because they have no a substitution.
In my opinion it is incorrect approach that if range adaptors will be adopted the set of standard algorithms should not be changed. I think that the range adapters are only one of possibilities. I am sure that despite of existense of range adapters many programmers will use for example for_first_if because it is simpler, clear, more effective and does not require piling up many constructions. The set of algorithms should be complete, consistent and sutisfy many requirements of users.
I am sure that despite of existense of range adapters many programmers will use for example for_first_if because it is simpler, clear, more effective and does not require piling up many constructions. The set of algorithms should be complete, consistent and sutisfy many requirements of users.
On Thursday, June 7, 2012 5:51:55 PM UTC+1, (unknown) wrote:I am sure that despite of existense of range adapters many programmers will use for example for_first_if because it is simpler, clear, more effective and does not require piling up many constructions. The set of algorithms should be complete, consistent and sutisfy many requirements of users.I am sure that the vast majority of C++ programmers use only non-trivial standard algorithms like std::sort or do not use standard algorithms at all. The most useful library components are those which are widely used and those which implement non-trivial functionality. I believe that we have much more serious problems than the lack of for_first_if. For example, it's a real shame that in 2012 we can't pass a filename consisting of wide characters to std::fstream.
I am sure that the vast majority of C++ programmers use only non-trivial standard algorithms like std::sort or do not use standard algorithms at all. The most useful library components are those which are widely used and those which implement non-trivial functionality. I believe that we have much more serious problems than the lack of for_first_if. For example, it's a real shame that in 2012 we can't pass a filename consisting of wide characters to std::fstream.Well. then please make a proposal to exclude from the Standard the following algorithms as for_each, copy, copy_if, copy_backward, find, find_if and so on
because thay are all trivial. :)
I understand that you are busy by solving global problems but from my point of view the Standard shall have a complete and consistent set of functions even if they are trivial.