[Rcpp-commits] r1687 - in pkg/Rcpp: inst/include/Rcpp src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jun 23 20:57:48 CEST 2010


Author: romain
Date: 2010-06-23 20:57:48 +0200 (Wed, 23 Jun 2010)
New Revision: 1687

Modified:
   pkg/Rcpp/inst/include/Rcpp/DateVector.h
   pkg/Rcpp/src/DateVector.cpp
Log:
ctors use initialization lists

Modified: pkg/Rcpp/inst/include/Rcpp/DateVector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/DateVector.h	2010-06-23 18:55:12 UTC (rev 1686)
+++ pkg/Rcpp/inst/include/Rcpp/DateVector.h	2010-06-23 18:57:48 UTC (rev 1687)
@@ -32,11 +32,12 @@
 		typedef std::vector<Date>::iterator iterator ;
 		typedef std::vector<Date>::const_iterator const_iterator ;
 		
-		DateVector(SEXP vec);
+		// TODO: use a custom exception class instead of std::range_error
+		DateVector(SEXP vec) throw(std::range_error) ;
 		DateVector(int n);
 		~DateVector() {};
-		const Date& operator()(unsigned int i) const;
-		Date& operator()(unsigned int i);
+		const Date& operator()(unsigned int i) const throw(std::range_error) ;
+		Date& operator()(unsigned int i) throw(std::range_error) ;
 		const Date& operator[](unsigned int i) const;
 		Date& operator[](unsigned int i);
 		int size() const;

Modified: pkg/Rcpp/src/DateVector.cpp
===================================================================
--- pkg/Rcpp/src/DateVector.cpp	2010-06-23 18:55:12 UTC (rev 1686)
+++ pkg/Rcpp/src/DateVector.cpp	2010-06-23 18:57:48 UTC (rev 1687)
@@ -25,7 +25,7 @@
 
 namespace Rcpp {
 
-	DateVector::DateVector(SEXP vec) {
+	DateVector::DateVector(SEXP vec) throw(std::range_error) : v()  {
 		int i;
 		if (!Rf_isNumeric(vec) || Rf_isMatrix(vec) || Rf_isLogical(vec))
 			throw std::range_error("DateVector: invalid numeric vector in constructor");
@@ -38,9 +38,7 @@
 	}
 
 
-	DateVector::DateVector(int n) {
-		v.resize(n);
-	}
+	DateVector::DateVector(int n) : v(n){}
 
 	const Date & DateVector::operator()(unsigned int i) const {
 		if (i >= v.size()) {



More information about the Rcpp-commits mailing list