Skip to content

Commit 9de884f

Browse files
committed
Merge pull request #216 from RcppCore/feature/pr211+pr212-const-iterator
Feature/pr211+pr212 const iterator
2 parents 8d5fb99 + 30e65b6 commit 9de884f

File tree

10 files changed

+36
-11
lines changed

10 files changed

+36
-11
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
RawVector and ExpressionVector, from the discussion with
88
Dirk Eddelbuettel and Kevin Ushey
99

10+
2014-11-30 Romain Francois <[email protected]>
11+
12+
* inst/include/Rcpp/vector/proxy.h: Const iteration correction
13+
* inst/include/Rcpp/sugar: Ditto in three files
14+
1015
2014-11-25 Dirk Eddelbuettel <[email protected]>
1116

1217
* inst/include/Rcpp/grow.h: Apply additional Shield<> use around tail

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: Rcpp
22
Title: Seamless R and C++ Integration
3-
Version: 0.11.3.2
4-
Date: 2014-11-23
3+
Version: 0.11.3.3
4+
Date: 2014-11-30
55
Author: Dirk Eddelbuettel, Romain Francois, JJ Allaire, Kevin Ushey,
66
Douglas Bates, and John Chambers
77
Maintainer: Dirk Eddelbuettel <[email protected]>

inst/NEWS.Rd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
as suggested by Martin Morgan on the rcpp-devel list.
1919
\item Sorting is now prohibited at compile time for objects of type
2020
\code{List}, \code{RawVector} and \code{ExpressionVector}.
21+
\item Vectors now have a \code{Vector::const\_iterator} that is 'const correct'
22+
thanks to fix by Romain following bug report in rcpp-devel by Martyn Plummer
2123
}
2224
\item Changes in Rcpp Attributes:
2325
\itemize{

inst/include/Rcpp/sugar/functions/setdiff.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// setdiff.h: Rcpp R/C++ interface class library -- setdiff
44
//
5-
// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2012 - 2014 Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -55,7 +55,7 @@ namespace sugar{
5555
Vector<RTYPE> get() const {
5656
int n = lhs_set.size() ;
5757
Vector<RTYPE> out = no_init(n) ;
58-
std::copy( lhs_set.begin(), lhs_set.end(), get_const_begin(out) ) ;
58+
std::copy( lhs_set.begin(), lhs_set.end(), out.begin() ) ;
5959
return out ;
6060
}
6161

@@ -120,7 +120,7 @@ namespace sugar{
120120
Vector<RTYPE> get() const {
121121
int n = intersect.size() ;
122122
Vector<RTYPE> out = no_init(n) ;
123-
std::copy( intersect.begin(), intersect.end(), get_const_begin(out) ) ;
123+
std::copy( intersect.begin(), intersect.end(), out.begin() ) ;
124124
return out ;
125125
}
126126

@@ -145,7 +145,7 @@ namespace sugar{
145145
Vector<RTYPE> get() const {
146146
int n = result.size() ;
147147
Vector<RTYPE> out = no_init(n) ;
148-
std::copy( result.begin(), result.end(), get_const_begin(out) ) ;
148+
std::copy( result.begin(), result.end(), out.begin() ) ;
149149
return out ;
150150
}
151151

inst/include/Rcpp/sugar/matrix/as_vector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// as_vector.h: Rcpp R/C++ interface class library -- as_vector( sugar matrix expression )
44
//
5-
// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2010 - 2014 Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -44,7 +44,7 @@ inline Rcpp::Vector<RTYPE>
4444
as_vector__impl( MatrixBase<RTYPE,NA,T>& t, Rcpp::traits::true_type ){
4545
Matrix<RTYPE>& ref = t.get_ref() ;
4646
int size = ref.ncol()*ref.nrow() ;
47-
typename Rcpp::Vector<RTYPE>::iterator first(static_cast<const Rcpp::Vector<RTYPE>&>(ref).begin()) ;
47+
typename Rcpp::Vector<RTYPE>::const_iterator first(static_cast<const Rcpp::Vector<RTYPE>&>(ref).begin()) ;
4848
return Vector<RTYPE>(first, first+size );
4949
}
5050

inst/include/Rcpp/sugar/nona/nona.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace sugar {
4646
public:
4747
typedef typename Rcpp::VectorBase<RTYPE,NA, Rcpp::Vector<RTYPE> > SUGAR_TYPE ;
4848
typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE ;
49-
typedef typename Rcpp::Vector<RTYPE>::iterator iterator ;
49+
typedef typename Rcpp::Vector<RTYPE>::const_iterator iterator ;
5050

5151
Nona( const SUGAR_TYPE& expr) : data(expr.get_ref().begin()), n(expr.size()){}
5252

inst/include/Rcpp/vector/MatrixColumn.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class MatrixColumn : public VectorBase<RTYPE,true,MatrixColumn<RTYPE> > {
4444

4545
MatrixColumn( const MATRIX& parent, int i ) :
4646
n(parent.nrow()),
47-
start(parent.begin() + i * n ),
47+
start( const_cast<MATRIX&>(parent).begin() + i * n ),
4848
const_start(parent.begin() + i *n)
4949
{
5050
if( i < 0 || i >= parent.ncol() ) throw index_out_of_bounds() ;

inst/include/Rcpp/vector/proxy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ namespace traits {
240240
};
241241
template <int RTYPE>
242242
struct r_vector_const_iterator {
243-
typedef typename storage_type<RTYPE>::type* type ;
243+
typedef const typename storage_type<RTYPE>::type* type ;
244244
};
245245

246246
template <int RTYPE> struct proxy_based_iterator{

inst/unitTests/cpp/Matrix.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,16 @@ NumericMatrix runit_no_init_matrix() {
225225
}
226226
return x;
227227
}
228+
229+
void runit_const_Matrix_column_set( NumericMatrix::Column& col1, const NumericMatrix::Column& col2 ){
230+
col1 = col2 ;
231+
}
232+
233+
// [[Rcpp::export]]
234+
NumericVector runit_const_Matrix_column( const NumericMatrix& m ){
235+
NumericMatrix::Column col1( m, 0 ) ;
236+
NumericMatrix::Column col2( m, 1 ) ;
237+
runit_const_Matrix_column_set(col1, col2) ;
238+
return col1 ;
239+
}
240+

inst/unitTests/runit.Matrix.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,10 @@ if (.runThisTest) {
165165
checkEquals(m, matrix(c(0, 1, 2, 3), nrow = 2))
166166
}
167167

168+
test.NumericMatrix.const.Column <- function(){
169+
m <- matrix(as.numeric(1:9), nrow = 3)
170+
res <- runit_const_Matrix_column(m)
171+
checkEquals( m[,1], m[,2] )
172+
}
168173

169174
}

0 commit comments

Comments
 (0)