mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Merge remote-tracking branch 'origin' into dev/neilmac/indextype
This commit is contained in:
commit
16d1e77568
15
.gitignore
vendored
15
.gitignore
vendored
@ -1 +1,14 @@
|
|||||||
tests/unittest-cpp
|
tests/unittest-cpp
|
||||||
|
CMakeFiles
|
||||||
|
tests/CMakeFiles
|
||||||
|
tests/Debug
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
tests/*tests.dir
|
||||||
|
*.vcxproj
|
||||||
|
*.vcxproj.filters
|
||||||
|
*.sln
|
||||||
|
*.tlog
|
||||||
|
Testing/Temporary/*.*
|
||||||
|
CMakeCache.txt
|
||||||
|
*.suo
|
||||||
|
@ -508,7 +508,7 @@ namespace details
|
|||||||
template <size_t Rank, bool Enabled = (Rank > 1), typename Ret = std::enable_if_t<Enabled, index<Rank - 1>>>
|
template <size_t Rank, bool Enabled = (Rank > 1), typename Ret = std::enable_if_t<Enabled, index<Rank - 1>>>
|
||||||
constexpr Ret shift_left(const index<Rank>& other) noexcept
|
constexpr Ret shift_left(const index<Rank>& other) noexcept
|
||||||
{
|
{
|
||||||
Ret ret;
|
Ret ret{};
|
||||||
for (size_t i = 0; i < Rank - 1; ++i)
|
for (size_t i = 0; i < Rank - 1; ++i)
|
||||||
{
|
{
|
||||||
ret[i] = other[i + 1];
|
ret[i] = other[i + 1];
|
||||||
@ -865,7 +865,7 @@ public:
|
|||||||
constexpr bounds_iterator& operator+=(difference_type n) noexcept
|
constexpr bounds_iterator& operator+=(difference_type n) noexcept
|
||||||
{
|
{
|
||||||
auto linear_idx = linearize(curr) + n;
|
auto linear_idx = linearize(curr) + n;
|
||||||
std::remove_const_t<value_type> stride;
|
std::remove_const_t<value_type> stride = 0;
|
||||||
stride[rank - 1] = 1;
|
stride[rank - 1] = 1;
|
||||||
for (size_t i = rank - 1; i-- > 0;)
|
for (size_t i = rank - 1; i-- > 0;)
|
||||||
{
|
{
|
||||||
|
@ -82,9 +82,9 @@ template<class T, class SizeType, const T Sentinel>
|
|||||||
array_view<T, dynamic_range> ensure_sentinel(const T* seq, SizeType max = std::numeric_limits<SizeType>::max())
|
array_view<T, dynamic_range> ensure_sentinel(const T* seq, SizeType max = std::numeric_limits<SizeType>::max())
|
||||||
{
|
{
|
||||||
auto cur = seq;
|
auto cur = seq;
|
||||||
while ((cur - seq) < max && *cur != Sentinel) ++cur;
|
while (SizeType(cur - seq) < max && *cur != Sentinel) ++cur;
|
||||||
fail_fast_assert(*cur == Sentinel);
|
fail_fast_assert(*cur == Sentinel);
|
||||||
return{ seq, cur - seq };
|
return{ seq, SizeType(cur - seq) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ array_view<T, dynamic_range> ensure_sentinel(const T* seq, SizeType max = std::n
|
|||||||
template<class T>
|
template<class T>
|
||||||
inline basic_string_view<T, dynamic_range> ensure_z(T* const & sz, std::ptrdiff_t max = PTRDIFF_MAX)
|
inline basic_string_view<T, dynamic_range> ensure_z(T* const & sz, std::ptrdiff_t max = PTRDIFF_MAX)
|
||||||
{
|
{
|
||||||
return ensure_sentinel<0>(sz, max);
|
return ensure_sentinel<T, size_t, 0>(sz, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO (neilmac) there is probably a better template-magic way to get the const and non-const overloads to share an implementation
|
// TODO (neilmac) there is probably a better template-magic way to get the const and non-const overloads to share an implementation
|
||||||
|
@ -79,6 +79,14 @@ SUITE(string_view_tests)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(TestConstructFromConstCharPointer)
|
||||||
|
{
|
||||||
|
const char* s = "Hello";
|
||||||
|
cstring_view<> v = ensure_z(s);
|
||||||
|
CHECK(v.length() == 5);
|
||||||
|
CHECK(v.used_length() == v.length());
|
||||||
|
}
|
||||||
|
|
||||||
TEST(TestConversionToConst)
|
TEST(TestConversionToConst)
|
||||||
{
|
{
|
||||||
char stack_string[] = "Hello";
|
char stack_string[] = "Hello";
|
||||||
|
Loading…
Reference in New Issue
Block a user