https://en.cppreference.com/w/cpp/iterator/iterator_traits
`std::iterator_traits` requires the following 5 types:
- `difference_type` - a signed integer type that can be used to identify distance between iterators
- `value_type` - the type of the values that can be obtained by dereferencing the iterator. This type is void for output iterators.
- `pointer` - defines a pointer to the type iterated over (value_type)
- `reference` - defines a reference to the type iterated over (value_type)
- `iterator_category` - the category of the iterator. Must be one of iterator category tags.
The current `const_iterator` for `rust::Vec<T>` only defined `value_type` and `reference` which caused an error when using `std::copy` on gcc 7.5.0 on Ubuntu but seemed to work fine on MacOS.
Checking this in check_type_ref allows it to apply anywhere that a
reference is written, such as return position which was not covered by
the previous logic.
After doing a `cargo publish` or `cargo package` we were getting a BUILD
file at target/package/cxx-0.2.11/BUILD which was subsequently picked up
by `bazel build ...`.
I'd like to give some more thought to how to expose this. Taking the
value by reference and copying it into the vector is nice when T is an
opaque C++ type but otherwise a pretty weird API from Rust.
Without this, on some compilers:
src/cxx.cc:252:30: error: specialization of ‘template<class T> rust::cxxbridge02::Vec<T>::Vec()’ in different namespace [-fpermissive]
rust::Vec<CXX_TYPE>::Vec() noexcept {
^
src/cxx.cc:274:3: note: in expansion of macro ‘RUST_VEC_OPS’
MACRO(u8, uint8_t)
^
src/cxx.cc:295:1: note: in expansion of macro ‘FOR_EACH_SIZED_PRIMITIVE’
FOR_EACH_SIZED_PRIMITIVE(RUST_VEC_OPS)
^
In file included from src/cxx.cc:1:0:
include/cxx.h:216:3: error: from definition of ‘template<class T> rust::cxxbridge02::Vec<T>::Vec()’ [-fpermissive]
Vec() noexcept;
^