Opened 11 years ago

Closed 9 years ago

Last modified 9 years ago

#5930 closed Feature Requests (wontfix)

data() for iterator_range

Reported by: olafvdspek@… 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 Steven Watanabe, 11 years ago

What exactly is iterator_range::data supposed to return?

comment:2 by Olaf van der Spek <olafvdspek@…>, 11 years ago

return empty() ? NULL : &front();

comment:3 by Steven Watanabe, 11 years ago

This is rather dangerous. It only works if the iterator points to contiguous storage.

comment:4 by Olaf van der Spek <olafvdspek@…>, 11 years ago

Right, it should only be provided in that case.

comment:5 by rhys.ulerich@…, 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.

in reply to:  5 ; comment:6 by Olaf van der Spek <olafvdspek@…>, 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 Olaf van der Spek <olafvdspek@…>, 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.

in reply to:  6 ; comment:8 by rhys.ulerich@…, 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?

in reply to:  8 ; comment:9 by Olaf van der Spek <olafvdspek@…>, 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.

in reply to:  9 comment:10 by rhys.ulerich@…, 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.

in reply to:  4 comment:11 by viboes, 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 anonymous, 9 years ago

I'm sure Google can give you enough real use cases for data(). It's a standard function.

comment:13 by Neil Groves, 9 years ago

Resolution: wontfix
Status: newclosed

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 anonymous, 9 years ago

But ISO C++ has data() as a member function, not as a non-member function.

Note: See TracTickets for help on using tickets.