File tree Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -176,6 +176,9 @@ class Slice final
176
176
Slice () noexcept ;
177
177
Slice (T *, std::size_t count) noexcept ;
178
178
179
+ template <typename C>
180
+ explicit Slice (C& c) : Slice(c.data(), c.size()) {}
181
+
179
182
Slice &operator =(const Slice<T> &) &noexcept = default ;
180
183
Slice &operator =(Slice<T> &&) &noexcept = default ;
181
184
Original file line number Diff line number Diff line change @@ -884,6 +884,12 @@ extern "C" const char *cxx_run_test() noexcept {
884
884
rust::String bad_utf16_rstring = rust::String::lossy (bad_utf16_literal);
885
885
ASSERT (bad_utf8_rstring == bad_utf16_rstring);
886
886
887
+ std::vector<int > cpp_vec{1 , 2 , 3 };
888
+ rust::Slice<int > slice_of_cpp_vec (cpp_vec);
889
+ ASSERT (slice_of_cpp_vec.data () == cpp_vec.data ());
890
+ ASSERT (slice_of_cpp_vec.size () == cpp_vec.size ());
891
+ ASSERT (slice_of_cpp_vec[0 ] == 1 );
892
+
887
893
rust::Vec<int > vec1{1 , 2 };
888
894
rust::Vec<int > vec2{3 , 4 };
889
895
swap (vec1, vec2);
You can’t perform that action at this time.
0 commit comments