Skip to content

Commit 276b2f5

Browse files
authored
Make array_view(pointer, size) constructor public (#666)
1 parent 9836238 commit 276b2f5

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

strings/base_array.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ WINRT_EXPORT namespace winrt
1717

1818
array_view() noexcept = default;
1919

20+
array_view(pointer data, size_type size) noexcept :
21+
m_data(data),
22+
m_size(size)
23+
{}
24+
2025
array_view(pointer first, pointer last) noexcept :
2126
m_data(first),
2227
m_size(static_cast<size_type>(last - first))
@@ -192,11 +197,6 @@ WINRT_EXPORT namespace winrt
192197

193198
protected:
194199

195-
array_view(pointer data, size_type size) noexcept :
196-
m_data(data),
197-
m_size(size)
198-
{}
199-
200200
pointer m_data{ nullptr };
201201
size_type m_size{ 0 };
202202

test/old_tests/UnitTests/array.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,24 @@ TEST_CASE("custom,DataReader")
126126
REQUIRE(3 == a[2]);
127127
}
128128

129+
//
130+
// This test illustrates an array_view<T> (non-const) bound to a raw buffer
131+
//
132+
TEST_CASE("buffer,DataReader")
133+
{
134+
auto reader = CreateDataReader({ 1, 2, 3 }).get();
135+
136+
std::array<byte, 3> a;
137+
byte* ptr = a.data();
138+
auto size = a.size();
139+
reader.ReadBytes({ ptr, static_cast<uint32_t>(size) });
140+
141+
REQUIRE(3 == a.size());
142+
REQUIRE(1 == a[0]);
143+
REQUIRE(2 == a[1]);
144+
REQUIRE(3 == a[2]);
145+
}
146+
129147
//
130148
// This test illustrates receiving an IVector and calling GetMany to fill an array.
131149
//
@@ -1259,6 +1277,7 @@ TEST_CASE("array_view,ctad")
12591277

12601278
uint8_t a[3]{};
12611279
REQUIRE_DEDUCED_AS(uint8_t, &a[0], &a[0]);
1280+
REQUIRE_DEDUCED_AS(uint8_t, &a[0], 3);
12621281
REQUIRE_DEDUCED_AS(uint8_t, a);
12631282

12641283
std::array<uint8_t, 3> ar{};

0 commit comments

Comments
 (0)