mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2024-11-23 23:29:50 +00:00
Touch up PR 538
This commit is contained in:
parent
ff01bbc1f7
commit
300072b5f3
@ -752,12 +752,14 @@ void Vec<T>::emplace_back(Args &&... args) {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Vec<T>::iterator::reference Vec<T>::iterator::operator*() const noexcept {
|
||||
typename Vec<T>::iterator::reference
|
||||
Vec<T>::iterator::operator*() const noexcept {
|
||||
return *static_cast<T *>(this->pos);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Vec<T>::iterator::pointer Vec<T>::iterator::operator->() const noexcept {
|
||||
typename Vec<T>::iterator::pointer
|
||||
Vec<T>::iterator::operator->() const noexcept {
|
||||
return static_cast<T *>(this->pos);
|
||||
}
|
||||
|
||||
@ -811,17 +813,17 @@ Vec<T>::iterator::operator-=(Vec<T>::iterator::difference_type n) noexcept {
|
||||
template <typename T>
|
||||
typename Vec<T>::iterator Vec<T>::iterator::operator+(
|
||||
Vec<T>::iterator::difference_type n) const noexcept {
|
||||
auto temp = iterator(*this);
|
||||
temp.pos = static_cast<char *>(this->pos) + this->stride * n;
|
||||
return temp;
|
||||
auto ret = iterator(*this);
|
||||
ret.pos = static_cast<char *>(this->pos) + this->stride * n;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Vec<T>::iterator Vec<T>::iterator::operator-(
|
||||
Vec<T>::iterator::difference_type n) const noexcept {
|
||||
auto temp = iterator(*this);
|
||||
temp.pos = static_cast<char *>(this->pos) - this->stride * n;
|
||||
return temp;
|
||||
auto ret = iterator(*this);
|
||||
ret.pos = static_cast<char *>(this->pos) - this->stride * n;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -829,7 +831,7 @@ typename Vec<T>::iterator::difference_type
|
||||
Vec<T>::iterator::operator-(const iterator &other) const noexcept {
|
||||
auto diff = std::distance(static_cast<char *>(other.pos),
|
||||
static_cast<char *>(this->pos));
|
||||
return diff / stride;
|
||||
return diff / this->stride;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -369,8 +369,7 @@ void c_take_rust_vec_shared_sort(rust::Vec<Shared> v) {
|
||||
// Exercise requirements of RandomAccessIterator.
|
||||
// https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator
|
||||
std::sort(v.begin(), v.end());
|
||||
if (v[0].z == 0 && v[1].z == 2 && v[2].z == 4 && v[3].z == 7)
|
||||
{
|
||||
if (v[0].z == 0 && v[1].z == 2 && v[2].z == 4 && v[3].z == 7) {
|
||||
cxx_test_suite_set_correct();
|
||||
}
|
||||
}
|
||||
|
@ -149,10 +149,13 @@ fn test_c_take() {
|
||||
check!(ffi::c_take_rust_vec_shared_forward_iterator(
|
||||
shared_test_vec,
|
||||
));
|
||||
let shared_sort_vec = vec![ffi::Shared { z: 2 }, ffi::Shared { z: 0 }, ffi::Shared { z: 7 }, ffi::Shared { z: 4 }];
|
||||
check!(ffi::c_take_rust_vec_shared_sort(
|
||||
shared_sort_vec,
|
||||
));
|
||||
let shared_sort_vec = vec![
|
||||
ffi::Shared { z: 2 },
|
||||
ffi::Shared { z: 0 },
|
||||
ffi::Shared { z: 7 },
|
||||
ffi::Shared { z: 4 },
|
||||
];
|
||||
check!(ffi::c_take_rust_vec_shared_sort(shared_sort_vec));
|
||||
check!(ffi::c_take_ref_rust_vec(&test_vec));
|
||||
check!(ffi::c_take_ref_rust_vec_index(&test_vec));
|
||||
check!(ffi::c_take_ref_rust_vec_copy(&test_vec));
|
||||
@ -207,7 +210,7 @@ fn test_c_method_calls() {
|
||||
assert_eq!(2021, unique_ptr.pin_mut().set(2021));
|
||||
assert_eq!(2021, unique_ptr.get());
|
||||
assert_eq!(2021, unique_ptr.get2());
|
||||
assert_eq!(2022, unique_ptr.pin_mut().set_succeed(2022).unwrap(),);
|
||||
assert_eq!(2022, unique_ptr.pin_mut().set_succeed(2022).unwrap());
|
||||
assert!(unique_ptr.pin_mut().get_fail().is_err());
|
||||
assert_eq!(2021, ffi::Shared { z: 0 }.c_method_on_shared());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user