auto iter1 = vec_str1.begin();
auto iter2 = vec_str2.begin();
while (iter1 != vec_str1.end() && iter2 != vec_str2.end())
{
http_client.add_header(*iter1, *iter2);
++iter1;
++iter2;
}
for (auto iter1 = vec_str1.begin(), iter2 = vec_str2.begin(); iter1 != vec_str1.end() && iter2 != vec_str2.end(); ++iter1, ++iter2)
{
http_client.add_header(*iter1, *iter2);
}
template<class... Conts>
auto zip_range(Conts&... conts) -> decltype(boost::make_iterator_range(
boost::make_zip_iterator(boost::make_tuple(conts.begin()...)),
boost::make_zip_iterator(boost::make_tuple(conts.end()...))
))
{
return {
boost::make_zip_iterator(boost::make_tuple(conts.begin()...)),
boost::make_zip_iterator(boost::make_tuple(conts.end()...))
};
}
for(auto&& t : zip_range(vec_str1, vec_str2))
{
http_client.add_header(t.get<0>(), t.get<1>());
}
for (auto header_name, header_value : vec_str1, vec_str2)
{
http_client.add_header(header_name, header_value);
}
On 2015–08–11, at 5:28 PM, Izzy Coding <matthew.i...@gmail.com> wrote:for(auto&& t : zip_range(vec_str1, vec_str2))
{
http_client.add_header(t.get<0>(), t.get<1>());
}
I have written up a quick draft proposal for this. Any feedback would be greatly appreciated.
https://drive.google.com/open?id=0B26UZ0CbMay5V25ZZUFXZDlILXM
E.G.
for ( var1 = x, var2 = 2; var1 <= var2; ++var1) { ... }
So to follow the same flow I wrote it as is.
I do not mind changing it if the masses prefer the other syntax.
for ( declaration ; iteration requirement; iteration action )...
compared to:
for ( declarations : iteration requirements and actions ) ...
As I mentioned before I am not tied to any particular syntax and would be happy to change. I just feel that the way I have defined it is easier to reason about the loop content given a long list of containers.
About the issue of the single auto&& in the declaration. This is just my simple way of writing it as this is a quick draft. I would indeed expect it to be more similar to:
for ( auto&& var1, auto&& var2 : con1, cont2 ) { ... }
Which would then allow for multiple different types in the declaration list. Unfortunately I am not a standardese pro and as such I more than likely have something wrong in my draft proposal.
In regards to the unpacking of multiple values to improve the boost::zip_iterator version of the code, I wonder if then we are suggestions that the zip_iterator or something similar should also be introduced into the standard? Also I would like to see what the ideas are around how the multiple return value stuff would affect this idea? Could someone provide an example of what using the multiple return value for statement would look like?
With regards to what if the containers are different in size, that is mentioned in my draft proposal. Basically the __end is equal the the first container end reached. Therefore no out of range exceptions can occur.
With regards to preference of the zip_iterator version. My main bugbare is the required boilerplate code in order for it to work. If the new multi-range-based for syntax could be used but essentially do the zip... Version stuff under the covers then I would be happy with that. My only other issues are those to do with clarity of the code.
for ( var1:cont1, ... )
UseVars(var9, var2, ...);
To me is much clearer and less prone to errors than:
for( auto&& t : zip_iterator( cont1, ... ) )
UseVars(t.get<9>(), t.get<2>(), ...);
Using the zip format it is difficult to know what each t.get refers to (I do understand that this is essentially the multiple value return idea, but that also then to me seems like it could bloat the declarations in the for statement). I am however not against that also being possible in the standard, but feel a clearer syntax would be better than depending on library iterator adapters and tuple style multiple return values. To me it is just much more clear and precise and easy to reason about.
https://drive.google.com/open?id=0B26UZ0CbMay5cXpRSmtqd09YR00
for-range-statement:
for-range-statement-list , ...
let the range-init be equivalent to a tuple-like structure containing the
required range-init for each of the declarations of a for-range-pair-
declaration.
tuple{ (expression1), ..., (expression{n}) };
The format "something , ..." Is what I thought denoted continuous optional additions. My intent is to make the list essentially variable in length.
Could you give an example of what you mean by defining auto&& __range1 through __rangeN? I am not sure how this could be written in standardese terms.
I would think the syntax defined in the draft proposal woul more easily allow this as well as being much more easy to understand and reason about.
for ( { auto&& item1, auto&& item2 } : tuple-range; auto&& single-value : container; { auto&& key1, auto&& value1 } : pair-range)
{
if (DoSomething(item1, item2, single-value))
{
DoSomethingElse(key1, value1);
}
}
How would something like this be expressed with only the multiple value return syntax?
>Note: It wasn't my intention to be speaking against the proposal
(looking back, I can see where that wouldn't be clear), only to note
that unpacking at least makes the 'zip' form less ugly.
I agree, having both options would be good and allow for developer preference. In my proposal there would still be the possibility to add the multiple return syntax as part of the other proposal or an extension of.
I will be completing my amendements to my proposal and hopefully getting a document number too. I would be greatful for any comments / error corrections to what I have as I know my wording is not quite right. I would be willing to have any help to perfect this proposal, and maybe afterwards I could also look at a proposal to extend the existing multiple return syntax with relation to my proposal also. Again any help / comments are welcome as I want to try and ensure the best possible fit for the proposal.
Current Draft Proposal Version:
https://drive.google.com/open?id=0B26UZ0CbMay5OGRORzkzZ1BiVWs
I hope it is much clearer than before. Any changes and amendments are welcome.
3) Using legacy for loop with boost::zip_iterator
Also with option 3 as I see it, there is a possibility for undefined behaviour if the for loop body modifies the ranges used. This is due to explicitly having stored each ranges end() iterator, which could potentially become an invalidated iterator on addition/removal of items from the container.
the subsequent dereferenced iterator is then assigned to the declared variable for use within the for statement body.
the __end of iteration should at the point of hitting the first of any range ends
However, when compiling with high warning levels it would be useful when possible to have a compiler warning about such mismatched ranges.
auto&& __range-declaration-N = *__beginN;
for-range-declaration-N = *__beginN;
for ( auto __begin = begin-expr, __end = end-expr; iterator-continuation-comparison; ++__begin )
auto&& __rangeN = ( expression ) /* or braced-init-list */ ;
auto __beginN = begin_exprN, __endN = end_exprN;
auto __beginN = begin_exprN;
auto __endN = end_exprN;
if any of the comparisons return a false result then the expression as a whole should be false and iteration should stop
>It might be worth mentioning the change made by the ranges >proposal should be incorporated - which uses instead
>...
What is the document number for the ranges proposal so I can add a reference to this as suggested?
Newly updated version is here:
https://drive.google.com/open?id=0B26UZ0CbMay5NGFDV3hUQk9hbjA
I hope this is closer to what it should be.
Note: this is an early draft. It’s known to be incomplete and incorrect, and it has lots of bad formatting.
This proposal should also consider changes based on the current working paper for "Ranges" [N4382]
where the iterator initialization for begin and end iterators are defined separately as they could
potentially be of differing types
A multi-range-based for statement
where iterator-continuation-comparison is equivalent to comparing
__beginN to its respective __endN using the not equal comparison for each
of the ranges declared
__beginN != __endN
and iteration-action is equivalent to incrementing __beginN for each of the ranges declared
New version can be found here:
https://drive.google.com/open?id=0B26UZ0CbMay5RG5NRERxWlBFNG8
Hope I have not missed anything.
--
---
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/.
Here is the new version:
https://drive.google.com/open?id=0B26UZ0CbMay5NGhsNmlnMjQtV0U
Latest version can be viewed here:
https://drive.google.com/open?id=0B26UZ0CbMay5THZlSFlPLXRBNzQ
Fingers crossed
Aha, yes, just spotted that one myself.
Consider that to be rectified.
As I said I would however be very interested in seeing a possible implementation for it.
I was possibly thinking about adding this addition into the proposal so that both possibilities are available as I believe that they have a close relation and should probably be implemented together.
I would be very interested to see that implementation. I only left that out as I don't currently understand how it would be possible to map from parallel_iter ranges to each of the parameters of the lamda. Also did not know if it was possible as how does the algorithm know the count of ranges in order to be able to specify the required parameters for the lamda?
As I said I would however be very interested in seeing a possible implementation for it.
I was possibly thinking about adding this addition into the proposal so that both possibilities are available as I believe that they have a close relation and should probably be implemented together.
I'm getting back at you when I get somewhere (in the night certainly).I was possibly thinking about adding this addition into the proposal so that both possibilities are available as I believe that they have a close relation and should probably be implemented together.
Yes if it is possible to complete.Also, I'm not a specialist so I don't know if I was breaking any standard guarantees.
OK I managed to make it work :)(I'll copy the full code at the end of this email to avoid losing it)
On 1 September 2015 at 01:36, Klaim - Joël Lamotte <mjk...@gmail.com> wrote:OK I managed to make it work :)(I'll copy the full code at the end of this email to avoid losing it)
The full code:
I hope you don't mind. I have added your example as a reference in my proposal. Hopefully this might spark further discussions around the library implementation version. However I do believe both versions have their own merits and probably should both be considered for standardisation.
Please find my latest version of the draft here:
https://drive.google.com/open?id=0B26UZ0CbMay5V2JWNUpfbkdyTUE
Still looking for any feedback. I will be submitting this proposal in the next few weeks ready to go out on committee mailing list before next committee meeting.
Sorry for late reply, sadly my daughter passed away so I have been with family.
I hope you don't mind. I have added your example as a reference in my proposal. Hopefully this might spark further discussions around the library implementation version. However I do believe both versions have their own merits and probably should both be considered for standardisation.
Please find my latest version of the draft here:
https://drive.google.com/open?id=0B26UZ0CbMay5V2JWNUpfbkdyTUE
Still looking for any feedback. I will be submitting this proposal in the next few weeks ready to go out on committee mailing list before next committee meeting.
By the way you might want to ask Eric Niebler his input if not already done.
By the way you might want to ask Eric Niebler his input if not already done.
How would I go about doing this?
Sorry for late reply, sadly my daughter passed away so I have been with family.
<snip>
Please find my latest version of the draft here:
https://drive.google.com/open?id=0B26UZ0CbMay5V2JWNUpfbkdyTUEStill looking for any feedback. I will be submitting this proposal in the next few weeks ready to go out on committee mailing list before next committee meeting.
I agree I am sure there is a way to be able to provide the functionality as a library feature. However I just don't know enough to be able to create it. Would be interested to work with someone who is more knowledgable in that area.
It's fairly straightforward to do "if r.begin() compiles, call it, otherwise call begin(r)" (with the usual caveats about immediate context).I'm not aware of any way to do "if the type of r has a member called 'begin', attempt to call r.begin(), otherwise call begin(r)" in normal C++ code, concepts or not. And the latter is what range-for does.In other words, the library solution would accept some types that range-for rejects.
If I understood you correctly (I'm not sure), this is already what std::begin does: http://en.cppreference.com/w/cpp/iterator/beginAlthough you need to use a using namespace declaration to benefit from ADL:template< class Container >void foo( Container&& container ){using namespace std; // allow to use std::begin if no Container's namespace specific begin() function is providedauto&& it = begin(container); // if no other option than std::begin() is selected here, if container.begin() exists, use it, otherwise fails to compile....}
namespace foo {
struct A { int begin; };
struct B { using end = int; };
class C { int* begin(); int *end(); }; // inaccessible
struct D { int* begin(int); int* end();};
struct E {};
template<class T> int* begin(const T&) { return nullptr; }
template<class T> int* end(const T&) { return nullptr; }
}
int main() {
foo::A a; foo::B b; foo::C c; foo::D d; foo::E e;
for(auto i1 : a) { } // doesn't compile
for(auto i2 : b) { } // doesn't compile
for(auto i3 : c) { } // doesn't compile
for(auto i4 : d) { } // doesn't compile
for(auto i5 : e) { } // compiles!
}
template<typename F, typename T...>
// requires F to be callable with all Ts as parameters
void for_each(T&& t..., F&& fn)
{
auto ranges = make_multirange(forward(t)...);
for(;ranges.current() != ranges.end(); ++ranges)
{
fn(ranges.get<>()...);
}
}
I know this kind of thing is not currently possible but this would seem the best approach and also allow other useful possibilities too. This code is assuming a tuple-like type for the collection of ranges.
ultimatley they would all be wrapped into an STL type that exibhits the required interface to the values passed in for the "for" statement to execute correctly.
Anything that is unable to be implemented within the wrapper type would be classed as invalid code.
I hope that all makes sense? I know my descriptive ability leave a fare bit to be desired. LOL
The latest version can be found here:
https://drive.google.com/open?id=0B26UZ0CbMay5dnZrWU5mcW9ZTFU
As always all comments and suggestions are welcome.