r/cpp • • Aug 11 '23

Making your own array

https://muit.xyz/posts/making-your-own-array/
12 Upvotes

39 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Aug 11 '23

[deleted]

2

u/[deleted] Aug 12 '23

[removed] — view removed comment

1

u/ts826848 Aug 12 '23

That checks whether an item is in an array, not whether an arbitrary pointer points inside an array (span?).

Granted, I'm not whether whether checking an arbitrary pointer is necessary. Maybe there's some self-nesting type for which checking items would not suffice?

1

u/[deleted] Aug 12 '23

[removed] — view removed comment

1

u/ts826848 Aug 13 '23

That strategy is not guaranteed to work, as described in the article you originally replied to.

1

u/[deleted] Aug 13 '23

[removed] — view removed comment

1

u/ts826848 Aug 13 '23

I'm not sure I'm understanding you correctly. So given a T* item and std::span<T> span, you're saying to check whether item points inside span you get char* ptr = reinterpret_cast<char*>(item) then... what?