Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add constructors for C-array, std::array<>, container ? #11

Open
martinmoene opened this issue Jan 13, 2019 · 5 comments
Open

Add constructors for C-array, std::array<>, container ? #11

martinmoene opened this issue Jan 13, 2019 · 5 comments

Comments

@martinmoene
Copy link
Owner

No description provided.

@Quuxplusone
Copy link

Add constructors for C-array, std::array<>, container ?

FWIW, I'd say "no"; let people use the two-iterator explicit constructor. Unless this is inspired by Ranges TS and would permit some interesting Ranges idiom that the two-iterator constructor doesn't?

@martinmoene
Copy link
Owner Author

Hi Arthur, Thanks for your reaction.

While issuing, I already felt some reluctance. It was simply inspired on std::span's constructors taking a container, however it's meaning with ring_span might be unclear.

@DBJDBJ
Copy link

DBJDBJ commented Feb 9, 2019

Perhaps ...

    // make from native arrays
template< typename T, size_t N >
inline nonstd::ring_span<T> make_ring_span(T(&arr)[N]) {
	return nonstd::ring_span<T>(arr, arr + N, arr, N);
}

// make from std arrays
template< typename T, size_t N >
inline nonstd::ring_span<T> make_ring_span(std::array<T,N> stdarr) 
{
	auto arr = stdarr.data();
	return nonstd::ring_span<T>(arr, arr + N, arr, N);
}

@martinmoene
Copy link
Owner Author

Or perhaps assume initially empty buffer:

return nonstd::ring_span<T>(&arr[0], &arr[0] + N, &arr[0], 0);
//                                                         ^     v
return nonstd::ring_span<T>(arr.begin(), arr.end(), arr.begin(), 0);

@DBJDBJ
Copy link

DBJDBJ commented Feb 14, 2019

I am not that familiar with the API ... but if the last argument is the size of the view on the source, that is OK of course.

There are numerous make_ring_span overloads one can imagine ... a project can add them gradually as it evolves or good contributors can add them to a (git) submodule ... called let's say 'makers'

          template< typename T >
          inline nonstd::ring_span<T> make_ring_span(std::vector<T> ) ;

          template< typename T >
          inline nonstd::ring_span<T> make_ring_span(std::basic_string<T> ) ;

          template< typename T >
          inline nonstd::ring_span<T> make_ring_span(std::unique_pointer<T[]>, size_t ) ;

         // then shared_ptr, map's set's and enyuthing else that has begin and end
         // or is otherwise applicable

I assume C++20 types are out of the question ... std::range as so on..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants