Skip to content

Mark r_vector::const_iterator::operator* as const #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# cpp11 (development version)

* `r_vector::const_iterator::operator*` is now a const method (#113, @bkietz, @xhochy)

# cpp11 0.2.2

* `r_bool` added as an adapter between `bool` and `Rboolean` values (#57, @bkietz)
Expand Down
78 changes: 39 additions & 39 deletions cpp11test/R/cpp11.R
Original file line number Diff line number Diff line change
@@ -1,157 +1,157 @@
# Generated by cpp11: do not edit by hand

cpp11_add_vec_for_ <- function(x, num) {
.Call("_cpp11test_cpp11_add_vec_for_", x, num)
.Call("_cpp11test_cpp11_add_vec_for_", x, num, PACKAGE = "cpp11test")
}

data_frame_ <- function() {
.Call("_cpp11test_data_frame_")
.Call("_cpp11test_data_frame_", PACKAGE = "cpp11test")
}

remove_altrep <- function(x) {
.Call("_cpp11test_remove_altrep", x)
.Call("_cpp11test_remove_altrep", x, PACKAGE = "cpp11test")
}

upper_bound <- function(x, breaks) {
.Call("_cpp11test_upper_bound", x, breaks)
.Call("_cpp11test_upper_bound", x, breaks, PACKAGE = "cpp11test")
}

findInterval2 <- function(x, breaks) {
.Call("_cpp11test_findInterval2", x, breaks)
.Call("_cpp11test_findInterval2", x, breaks, PACKAGE = "cpp11test")
}

findInterval2_5 <- function(x, breaks) {
.Call("_cpp11test_findInterval2_5", x, breaks)
.Call("_cpp11test_findInterval2_5", x, breaks, PACKAGE = "cpp11test")
}

findInterval3 <- function(x, breaks) {
.Call("_cpp11test_findInterval3", x, breaks)
.Call("_cpp11test_findInterval3", x, breaks, PACKAGE = "cpp11test")
}

findInterval4 <- function(x, breaks) {
.Call("_cpp11test_findInterval4", x, breaks)
.Call("_cpp11test_findInterval4", x, breaks, PACKAGE = "cpp11test")
}

grow_ <- function(n) {
.Call("_cpp11test_grow_", n)
.Call("_cpp11test_grow_", n, PACKAGE = "cpp11test")
}

cpp11_insert_ <- function(num_sxp) {
.Call("_cpp11test_cpp11_insert_", num_sxp)
.Call("_cpp11test_cpp11_insert_", num_sxp, PACKAGE = "cpp11test")
}

gibbs_cpp <- function(N, thin) {
.Call("_cpp11test_gibbs_cpp", N, thin)
.Call("_cpp11test_gibbs_cpp", N, thin, PACKAGE = "cpp11test")
}

gibbs_cpp2 <- function(N, thin) {
.Call("_cpp11test_gibbs_cpp2", N, thin)
.Call("_cpp11test_gibbs_cpp2", N, thin, PACKAGE = "cpp11test")
}

gibbs_rcpp <- function(N, thin) {
.Call("_cpp11test_gibbs_rcpp", N, thin)
.Call("_cpp11test_gibbs_rcpp", N, thin, PACKAGE = "cpp11test")
}

gibbs_rcpp2 <- function(N, thin) {
.Call("_cpp11test_gibbs_rcpp2", N, thin)
.Call("_cpp11test_gibbs_rcpp2", N, thin, PACKAGE = "cpp11test")
}

row_sums <- function(x) {
.Call("_cpp11test_row_sums", x)
.Call("_cpp11test_row_sums", x, PACKAGE = "cpp11test")
}

protect_one_ <- function(x, n) {
invisible(.Call("_cpp11test_protect_one_", x, n))
invisible(.Call("_cpp11test_protect_one_", x, n, PACKAGE = "cpp11test"))
}

protect_one_sexp_ <- function(x, n) {
invisible(.Call("_cpp11test_protect_one_sexp_", x, n))
invisible(.Call("_cpp11test_protect_one_sexp_", x, n, PACKAGE = "cpp11test"))
}

protect_one_cpp11_ <- function(x, n) {
invisible(.Call("_cpp11test_protect_one_cpp11_", x, n))
invisible(.Call("_cpp11test_protect_one_cpp11_", x, n, PACKAGE = "cpp11test"))
}

protect_one_preserve_ <- function(x, n) {
invisible(.Call("_cpp11test_protect_one_preserve_", x, n))
invisible(.Call("_cpp11test_protect_one_preserve_", x, n, PACKAGE = "cpp11test"))
}

protect_many_ <- function(n) {
invisible(.Call("_cpp11test_protect_many_", n))
invisible(.Call("_cpp11test_protect_many_", n, PACKAGE = "cpp11test"))
}

protect_many_cpp11_ <- function(n) {
invisible(.Call("_cpp11test_protect_many_cpp11_", n))
invisible(.Call("_cpp11test_protect_many_cpp11_", n, PACKAGE = "cpp11test"))
}

protect_many_sexp_ <- function(n) {
invisible(.Call("_cpp11test_protect_many_sexp_", n))
invisible(.Call("_cpp11test_protect_many_sexp_", n, PACKAGE = "cpp11test"))
}

protect_many_preserve_ <- function(n) {
invisible(.Call("_cpp11test_protect_many_preserve_", n))
invisible(.Call("_cpp11test_protect_many_preserve_", n, PACKAGE = "cpp11test"))
}

protect_many_rcpp_ <- function(n) {
invisible(.Call("_cpp11test_protect_many_rcpp_", n))
invisible(.Call("_cpp11test_protect_many_rcpp_", n, PACKAGE = "cpp11test"))
}

cpp11_release_ <- function(n) {
invisible(.Call("_cpp11test_cpp11_release_", n))
invisible(.Call("_cpp11test_cpp11_release_", n, PACKAGE = "cpp11test"))
}

rcpp_release_ <- function(n) {
invisible(.Call("_cpp11test_rcpp_release_", n))
invisible(.Call("_cpp11test_rcpp_release_", n, PACKAGE = "cpp11test"))
}

cpp11_safe_ <- function(x_sxp) {
.Call("_cpp11test_cpp11_safe_", x_sxp)
.Call("_cpp11test_cpp11_safe_", x_sxp, PACKAGE = "cpp11test")
}

sum_int_for_ <- function(x) {
.Call("_cpp11test_sum_int_for_", x)
.Call("_cpp11test_sum_int_for_", x, PACKAGE = "cpp11test")
}

rcpp_sum_dbl_for_ <- function(x_sxp) {
.Call("_cpp11test_rcpp_sum_dbl_for_", x_sxp)
.Call("_cpp11test_rcpp_sum_dbl_for_", x_sxp, PACKAGE = "cpp11test")
}

rcpp_sum_dbl_foreach_ <- function(x_sxp) {
.Call("_cpp11test_rcpp_sum_dbl_foreach_", x_sxp)
.Call("_cpp11test_rcpp_sum_dbl_foreach_", x_sxp, PACKAGE = "cpp11test")
}

rcpp_sum_dbl_accumulate_ <- function(x_sxp) {
.Call("_cpp11test_rcpp_sum_dbl_accumulate_", x_sxp)
.Call("_cpp11test_rcpp_sum_dbl_accumulate_", x_sxp, PACKAGE = "cpp11test")
}

rcpp_grow_ <- function(n_sxp) {
.Call("_cpp11test_rcpp_grow_", n_sxp)
.Call("_cpp11test_rcpp_grow_", n_sxp, PACKAGE = "cpp11test")
}

sum_dbl_for_ <- function(x) {
.Call("_cpp11test_sum_dbl_for_", x)
.Call("_cpp11test_sum_dbl_for_", x, PACKAGE = "cpp11test")
}

sum_dbl_for2_ <- function(x_sxp) {
.Call("_cpp11test_sum_dbl_for2_", x_sxp)
.Call("_cpp11test_sum_dbl_for2_", x_sxp, PACKAGE = "cpp11test")
}

sum_dbl_for3_ <- function(x_sxp) {
.Call("_cpp11test_sum_dbl_for3_", x_sxp)
.Call("_cpp11test_sum_dbl_for3_", x_sxp, PACKAGE = "cpp11test")
}

sum_dbl_foreach_ <- function(x) {
.Call("_cpp11test_sum_dbl_foreach_", x)
.Call("_cpp11test_sum_dbl_foreach_", x, PACKAGE = "cpp11test")
}

sum_dbl_foreach2_ <- function(x_sxp) {
.Call("_cpp11test_sum_dbl_foreach2_", x_sxp)
.Call("_cpp11test_sum_dbl_foreach2_", x_sxp, PACKAGE = "cpp11test")
}

sum_dbl_accumulate_ <- function(x) {
.Call("_cpp11test_sum_dbl_accumulate_", x)
.Call("_cpp11test_sum_dbl_accumulate_", x, PACKAGE = "cpp11test")
}

sum_dbl_accumulate2_ <- function(x_sxp) {
.Call("_cpp11test_sum_dbl_accumulate2_", x_sxp)
.Call("_cpp11test_sum_dbl_accumulate2_", x_sxp, PACKAGE = "cpp11test")
}
2 changes: 1 addition & 1 deletion inst/include/cpp11/list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ inline void r_vector<SEXP>::const_iterator::fill_buf(R_xlen_t) {
}

template <>
inline SEXP r_vector<SEXP>::const_iterator::operator*() {
inline SEXP r_vector<SEXP>::const_iterator::operator*() const {
return VECTOR_ELT(data_->data(), pos_);
}

Expand Down
10 changes: 5 additions & 5 deletions inst/include/cpp11/r_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class r_vector {
inline bool operator!=(const const_iterator& other) const;
inline bool operator==(const const_iterator& other) const;

inline T operator*();
inline T operator*() const;

friend class writable::r_vector<T>::iterator;

Expand Down Expand Up @@ -265,7 +265,7 @@ class r_vector : public cpp11::r_vector<T> {

inline iterator& operator++();

inline proxy operator*();
inline proxy operator*() const;

using cpp11::r_vector<T>::const_iterator::operator!=;

Expand Down Expand Up @@ -554,7 +554,7 @@ inline typename cpp11::r_vector<T>::const_iterator cpp11::r_vector<T>::find(
}

template <typename T>
inline T r_vector<T>::const_iterator::operator*() {
inline T r_vector<T>::const_iterator::operator*() const {
if (data_->is_altrep()) {
return buf_[pos_ - block_start_];
} else {
Expand Down Expand Up @@ -586,9 +586,9 @@ r_vector<T>::proxy::proxy(SEXP data, const R_xlen_t index, T* const p, bool is_a
: data_(data), index_(index), p_(p), is_altrep_(is_altrep) {}

template <typename T>
inline typename r_vector<T>::proxy r_vector<T>::iterator::operator*() {
inline typename r_vector<T>::proxy r_vector<T>::iterator::operator*() const {
if (data_.is_altrep()) {
return proxy(data_.data(), pos_, &buf_[pos_ - block_start_], true);
return proxy(data_.data(), pos_, const_cast<T*>(&buf_[pos_ - block_start_]), true);
} else {
return proxy(data_.data(), pos_,
data_.data_p_ != nullptr ? &data_.data_p_[pos_] : nullptr, false);
Expand Down
2 changes: 1 addition & 1 deletion inst/include/cpp11/strings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ inline void r_vector<r_string>::const_iterator::fill_buf(R_xlen_t) {
}

template <>
inline r_string r_vector<r_string>::const_iterator::operator*() {
inline r_string r_vector<r_string>::const_iterator::operator*() const {
return STRING_ELT(data_->data(), pos_);
}

Expand Down