#5930 closed Feature Requests (wontfix)
data() for iterator_range
Reported by: | Owned by: | Neil Groves | |
---|---|---|---|
Milestone: | To Be Determined | Component: | range |
Version: | Boost 1.47.0 | Severity: | Problem |
Keywords: | Cc: |
Description
Could you add the data() member to iterator_range?
Change History (14)
comment:1 by , 11 years ago
comment:3 by , 11 years ago
This is rather dangerous. It only works if the iterator points to contiguous storage.
follow-up: 6 comment:5 by , 11 years ago
How can a member method be provided only under certain runtime conditions? It seems the existing class methods do what one needs and that data() could be written as a free function.
follow-up: 8 comment:6 by , 11 years ago
Replying to rhys.ulerich@…:
How can a member method be provided only under certain runtime conditions?
It's not a runtime condition.
It seems the existing class methods do what one needs and that data() could be written as a free function.
A free function that'd work for all containers / ranges that support random access would be fine too.
comment:7 by , 11 years ago
Except that C++11 has data() for array, string, vector and probably others, so there's probably a good reason against a free function.
follow-up: 9 comment:8 by , 11 years ago
Referring to...
return empty() ? NULL : &front();
This is rather dangerous. It only works if the iterator points to contiguous storage.
Right, it should only be provided in that case.
I asked...
How can a member method be provided only under certain runtime conditions?
It's not a runtime condition.
An iterator_range knowing that it represents a contiguous region of memory seems like a runtime condition to me. What am I missing?
follow-up: 10 comment:9 by , 11 years ago
Replying to rhys.ulerich@…:
An iterator_range knowing that it represents a contiguous region of memory seems like a runtime condition to me. What am I missing?
It's a compile time condition. True for pointers, arrays, array, vector and string. False for a lot of other things.
comment:10 by , 11 years ago
An iterator_range knowing that it represents a contiguous region of memory seems like a runtime condition to me. What am I missing?
It's a compile time condition. True for pointers, arrays, array, vector and string. False for a lot of other things.
Ahh.. Good point. My mistake.
comment:11 by , 9 years ago
Replying to Olaf van der Spek <olafvdspek@…>:
Right, it should only be provided in that case.
How the user could know that the function is provided only under some special circumstances? Could you show a real use case?
comment:12 by , 9 years ago
I'm sure Google can give you enough real use cases for data(). It's a standard function.
comment:13 by , 9 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
While a member data() function exists for some containers in the standard library it does not make sense to conditionally add this to iterator_range.
If you know enough about the iterator that this function can work then it is trivial to implement a non-member function that is more broadly applicable.
comment:14 by , 9 years ago
But ISO C++ has data() as a member function, not as a non-member function.
What exactly is iterator_range::data supposed to return?