mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
add as_span overload for basic_string which doesn't have nonconst .data() like other contiguous containers
This commit is contained in:
parent
04050a2162
commit
e4d8d35af5
@ -1568,6 +1568,14 @@ template <typename Cont>
|
|||||||
constexpr auto as_span(Cont &&arr) -> std::enable_if_t<!details::is_span<std::decay_t<Cont>>::value,
|
constexpr auto as_span(Cont &&arr) -> std::enable_if_t<!details::is_span<std::decay_t<Cont>>::value,
|
||||||
span<std::remove_reference_t<decltype(arr.size(), *arr.data())>, dynamic_range>> = delete;
|
span<std::remove_reference_t<decltype(arr.size(), *arr.data())>, dynamic_range>> = delete;
|
||||||
|
|
||||||
|
// from basic_string which doesn't have nonconst .data() member like other contiguous containers
|
||||||
|
template <typename CharT, typename Traits, typename Allocator>
|
||||||
|
constexpr auto as_span(std::basic_string<CharT, Traits, Allocator> &str) -> span<CharT, dynamic_range>
|
||||||
|
{
|
||||||
|
fail_fast_assert(str.size() < PTRDIFF_MAX);
|
||||||
|
return {&str[0], static_cast<std::ptrdiff_t>(str.size())};
|
||||||
|
}
|
||||||
|
|
||||||
template <typename ValueType, size_t Rank>
|
template <typename ValueType, size_t Rank>
|
||||||
class strided_span
|
class strided_span
|
||||||
{
|
{
|
||||||
|
@ -203,6 +203,15 @@ SUITE(span_tests)
|
|||||||
overloaded_func(av3.as_span(dim<>(1), dim<3>(), dim<5>()), 't');
|
overloaded_func(av3.as_span(dim<>(1), dim<3>(), dim<5>()), 't');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
string str;
|
||||||
|
span<char> strspan = as_span(str);
|
||||||
|
(void)strspan;
|
||||||
|
const string cstr;
|
||||||
|
span<const char> cstrspan = as_span(cstr);
|
||||||
|
(void)cstrspan;
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
int a[3][4][5];
|
int a[3][4][5];
|
||||||
auto av = as_span(a);
|
auto av = as_span(a);
|
||||||
|
Loading…
Reference in New Issue
Block a user