20#ifndef Rcpp__vector__Vector_h
21#define Rcpp__vector__Vector_h
27template <
int RTYPE,
template <
class>
class StoragePolicy = PreserveStorage >
29 public StoragePolicy< Vector<RTYPE,StoragePolicy> >,
34 public VectorBase< RTYPE, true, Vector<RTYPE,StoragePolicy> >
64 Storage::copy__(
other) ;
68 return Storage::copy__(rhs) ;
76 template <
typename Proxy>
89 RCPP_DEBUG_2(
"Vector<%d>( const T& size = %d, const stored_type& u )", RTYPE,
size)
95 RCPP_DEBUG_2(
"Vector<%d>( const int& size = %d, const stored_type& u )", RTYPE,
size)
102 RCPP_DEBUG_2(
"Vector<%d>( const std::string& = %s )", RTYPE,
st.c_str() )
115 RCPP_DEBUG_2(
"Vector<%d>( const int& siz = %s, stored_type (*gen)(void) )", RTYPE, siz )
121 template <
typename T>
136 if(
dims.size() > 1 ){
144 template <
typename T>
151 template <
typename U>
153 RCPP_DEBUG_2(
"Vector<%d>( const Dimension& (%d), const U& )", RTYPE,
dims.size() )
156 if(
dims.size() > 1 ){
161 template <
bool NA,
typename VEC>
163 RCPP_DEBUG_2(
"Vector<%d>( const VectorBase<RTYPE,NA,VEC>& ) [VEC = %s]", RTYPE,
DEMANGLE(VEC) )
167 template <
typename T,
typename U>
175 template <
bool NA,
typename T>
179 RCPP_DEBUG_2(
"Vector<%d>( const sugar::SingleLogicalResult<NA,T>& ) [T = %s]", RTYPE,
DEMANGLE(T) )
182 template <
typename T,
typename U1>
186 RCPP_DEBUG_2(
"const T& siz, stored_type (*gen)(U1), const U1& u1 )", RTYPE, siz )
191 template <
typename T,
typename U1,
typename U2>
195 RCPP_DEBUG_2(
"const T& siz, stored_type (*gen)(U1,U2), const U1& u1, const U2& u2)", RTYPE, siz )
200 template <
typename T,
typename U1,
typename U2,
typename U3>
204 RCPP_DEBUG_2(
"const T& siz, stored_type (*gen)(U1,U2,U3), const U1& u1, const U2& u2, const U3& u3)", RTYPE, siz )
209 template <
typename InputIterator>
211 RCPP_DEBUG_1(
"Vector<%d>( InputIterator first, InputIterator last", RTYPE )
216 template <
typename InputIterator,
typename T>
220 RCPP_DEBUG_2(
"Vector<%d>( InputIterator first, InputIterator last, T n = %d)", RTYPE, n )
224 template <
typename InputIterator,
typename Func>
227 RCPP_DEBUG_1(
"Vector<%d>( InputIterator, InputIterator, Func )", RTYPE )
231 template <
typename InputIterator,
typename Func,
typename T>
235 RCPP_DEBUG_2(
"Vector<%d>( InputIterator, InputIterator, Func, T n = %d )", RTYPE, n )
239#ifdef HAS_CXX0X_INITIALIZER_LIST
240 Vector( std::initializer_list<init_type> list ) {
241 assign( list.begin() , list.end() ) ;
245 template <
typename T>
252 return traits::get_na<RTYPE>();
255 return traits::is_na<RTYPE>(x);
258 #ifdef RCPP_COMMA_INITIALIZATION
269 return ::Rf_xlength( Storage::get__() ) ;
276 return ::Rf_xlength( Storage::get__() ) ;
287 const int nrow =
dim[0] ;
288 const int ncol =
dim[1] ;
290 const char*
fmt =
"Location index is out of bounds: "
291 "[row index=%i; row extent=%i; "
292 "column index=%i; column extent=%i].";
295 return i +
static_cast<R_xlen_t>(nrow)*j ;
304 const char*
fmt =
"Index out of bounds: [index=%i; extent=%i].";
323 const char*
fmt =
"Index out of bounds: [index='%s'].";
328 template <
typename U>
379 return RObject( Storage::get__() );
383 template <
int RHS_RTYPE,
bool RHS_NA,
typename RHS_T>
392 template <
int RHS_RTYPE,
bool RHS_NA,
typename RHS_T>
407 internal::Sort_is_not_allowed_for_this_type<RTYPE>::do_nothing();
428 template <
typename InputIterator>
438 template <
typename InputIterator>
445 template <
typename InputIterator,
typename F>
450 template <
typename T>
457 template <
typename T>
458 void push_back(
const T&
object,
const std::string& name ){
464 template <
typename T>
470 template <
typename T>
477 template <
typename T>
484 template <
typename T>
509 cache.update(*
this) ;
512 template <
typename U>
518 template <
typename U>
523 template <
typename U>
528 template <
typename U>
536 template <
typename U>
550 template <
typename EXPR_VEC>
559 if( ! traits::is_na<RTYPE>(
left ) ){
567 template <
typename EXPR_VEC>
574 if( ! traits::is_na<RTYPE>(start[i]) ){
605 std::stringstream
ss;
606 ss <<
"no name '" << name <<
"' found";
617 RCPP_DEBUG_2(
"VECTOR<%d>::init( SEXP = <%p> )", RTYPE, Storage::get__() )
646 Storage::set__( target.get__() ) ;
671 Storage::set__( target.get__() ) ;
699 Storage::set__( target.get__() ) ;
726 Storage::set__( target.get__() ) ;
753 Storage::set__( target.get__() ) ;
779 Storage::set__( target.get__() ) ;
809 Storage::set__( target.get__() ) ;
838 Storage::set__( target.get__() ) ;
879 Storage::set__( target.get__() ) ;
919 Storage::set__( target.get__() ) ;
934 const char*
fmt =
"Iterator index is out of bounds: "
935 "[iterator index=%i; iterator extent=%i]";
955 Storage::set__( target.get__() ) ;
972 Storage::set__( target.get__() ) ;
978 if(
first >
last )
throw std::range_error(
"invalid range") ;
992 const char*
fmt =
"Iterator index is out of bounds: "
993 "[iterator=%s; index=%i; extent=%i]";
1030 Storage::set__( target.get__() ) ;
1036 template <
typename T>
1039 if( n == x.size() ){
1051 template <
typename T>
1057 template <
typename T>
1065 template <
bool NA,
typename VEC>
1067 RCPP_DEBUG_4(
"Vector<%d>::import_sugar_expression( VectorBase<%d,%d,%s>, false_type )", RTYPE,
NA, RTYPE,
DEMANGLE(VEC) ) ;
1074 template <
bool NA,
typename VEC>
1076 RCPP_DEBUG_4(
"Vector<%d>::import_sugar_expression( VectorBase<%d,%d,%s>, true_type )", RTYPE,
NA, RTYPE,
DEMANGLE(VEC) ) ;
1077 Storage::set__(
other.get_ref() ) ;
1081 template <
typename T>
1087 template <
typename T>
1092 template <
typename T>
1099 template <
typename T>
1104 template <
typename U>
1114 template <
typename U>
1125 #if defined(HAS_VARIADIC_TEMPLATES)
1127 template <
typename... T>
1130 traits::is_any_named<T...>::value
1135 template <
typename... T>
1137 Vector res(
sizeof...(T)) ;
1142 template <
typename... T>
1144 Vector res(
sizeof...(T)) ;
1149 res.attr(
"names") =
names;
1152 template <
typename T>
1157 template <
typename T,
typename...
TArgs>
1162 template <
typename T>
1166 template <
typename T,
typename...
TArgs>
1172 #include <Rcpp/generated/Vector__create.h>
1182 return Rcpp_eval( Storage::get__(), env );
1188template <
int RTYPE,
template <
class>
class StoragePolicy >
1192 typename VECTOR::iterator i =
const_cast<VECTOR &
>(rhs).begin();
1193 typename VECTOR::iterator
iend =
const_cast<VECTOR &
>(rhs).end();
1199 for ( ; i !=
iend; ++i) {
1207template<
template <
class>
class StoragePolicy >
1211 typename VECTOR::iterator i =
const_cast<VECTOR &
>(rhs).begin();
1212 typename VECTOR::iterator
iend =
const_cast<VECTOR &
>(rhs).end();
1215 s <<
"\"" << (*i) <<
"\"";
1218 for ( ; i !=
iend; ++i) {
1219 s <<
" \"" << (*i) <<
"\"";
AttributeProxy attr(const std::string &name)
void fill_or_generate__impl(const T &t, traits::false_type)
traits::storage_type< RTYPE >::type stored_type
void fill_or_generate(const T &t)
iterator erase_range__impl(iterator first, iterator last)
static Vector import_transform(InputIterator first, InputIterator last, F f)
iterator erase(int position)
internal::RangeIndexer< RTYPE, true, Vector > Indexer
Vector & operator=(const T &x)
SEXP eval(SEXP env) const
Vector(const GenericProxy< Proxy > &proxy)
Vector(const T &size, const U &u, typename Rcpp::traits::enable_if< traits::is_arithmetic< T >::value, void >::type *=0)
Vector(const Dimension &dims)
R_xlen_t findName(const std::string &name) const
Vector(const T &size, const stored_type &u, typename Rcpp::traits::enable_if< traits::is_arithmetic< T >::value, void >::type *=0)
void push_front_name__impl(const stored_type &object, const std::string &name, traits::false_type)
void import_sugar_expression(const Rcpp::VectorBase< RTYPE, NA, VEC > &other, traits::true_type)
void push_back__impl(const stored_type &object, traits::true_type)
iterator erase_single__impl(iterator position)
traits::r_vector_cache_type< RTYPE, StoragePolicy >::type cache
const_Proxy operator[](R_xlen_t i) const
Vector & operator+=(const VectorBase< RTYPE, false, EXPR_VEC > &rhs)
void assign(InputIterator first, InputIterator last)
Vector & operator+=(const VectorBase< RTYPE, true, EXPR_VEC > &rhs)
void push_back_name__impl(const stored_type &object, const std::string &name, traits::true_type)
Vector(const std::string &st)
const_iterator begin() const
NameProxy operator[](const std::string &name) const
static bool is_na(stored_type x)
void push_front__impl(const stored_type &object, traits::true_type)
const_Proxy operator()(const size_t &i) const
void push_front_name__impl(const stored_type &object, const std::string &name, traits::true_type)
Vector(const Dimension &dims, const U &u)
Vector(const T &siz, stored_type(*gen)(void), typename Rcpp::traits::enable_if< traits::is_arithmetic< T >::value, void >::type *=0)
iterator insert__impl(iterator position, const stored_type &object_, traits::true_type)
bool containsElementNamed(const char *target) const
Proxy operator()(const size_t &i, const size_t &j)
traits::r_vector_const_iterator< RTYPE, StoragePolicy >::type const_iterator
static void replace_element__dispatch(traits::true_type, iterator it, SEXP names, R_xlen_t index, const U &u)
static void replace_element(iterator it, SEXP names, R_xlen_t index, const U &u)
Proxy operator[](R_xlen_t i)
void fill__dispatch(traits::false_type, const U &u)
const_Proxy operator()(const size_t &i, const size_t &j) const
Indexer operator[](const Range &range)
R_xlen_t offset(const int &i, const int &j) const
iterator insert(iterator position, const T &object)
Vector(const sugar::SingleLogicalResult< NA, T > &obj)
const_iterator end() const
NameProxy operator()(const std::string &name) const
static void replace_element__dispatch__isArgument(traits::false_type, iterator it, SEXP names, R_xlen_t index, const U &u)
traits::r_vector_name_proxy< RTYPE, StoragePolicy >::type NameProxy
traits::r_vector_proxy< RTYPE, StoragePolicy >::type value_type
const SubsetProxy< RTYPE, StoragePolicy, RHS_RTYPE, RHS_NA, RHS_T > operator[](const VectorBase< RHS_RTYPE, RHS_NA, RHS_T > &rhs) const
traits::r_vector_element_converter< RTYPE >::type converter_type
Vector(T size, typename Rcpp::traits::enable_if< traits::is_arithmetic< T >::value, void >::type *=0)
Vector(const T &siz, stored_type(*gen)(U1, U2), const U1 &u1, const U2 &u2, typename Rcpp::traits::enable_if< traits::is_arithmetic< T >::value, void >::type *=0)
void push_front(const T &object, const std::string &name)
Vector(const T &siz, stored_type(*gen)(U1), const U1 &u1, typename Rcpp::traits::enable_if< traits::is_arithmetic< T >::value, void >::type *=0)
void push_front__impl(const stored_type &object, traits::false_type)
static stored_type get_na()
void import_sugar_expression(const Rcpp::VectorBase< RTYPE, NA, VEC > &other, traits::false_type)
NameProxy operator()(const std::string &name)
void import_expression(const T &other, R_xlen_t n)
StoragePolicy< Vector > Storage
const_iterator cbegin() const
SubsetProxy< RTYPE, StoragePolicy, RHS_RTYPE, RHS_NA, RHS_T > operator[](const VectorBase< RHS_RTYPE, RHS_NA, RHS_T > &rhs)
void push_back(const T &object)
Vector(InputIterator first, InputIterator last, Func func, T n, typename Rcpp::traits::enable_if< traits::is_arithmetic< T >::value, void >::type *=0)
Vector(const int &size, const stored_type &u)
void push_front(const T &object)
R_xlen_t offset(const R_xlen_t &i) const
Proxy at(const size_t &i)
void assign_object(const T &x, traits::true_type)
static void replace_element__dispatch(traits::false_type, iterator it, SEXP names, R_xlen_t index, const U &u)
Vector(InputIterator first, InputIterator last, Func func)
const_Proxy at(const size_t &i) const
void push_back__impl(const stored_type &object, traits::false_type)
Vector(InputIterator first, InputIterator last)
NameProxy operator[](const std::string &name)
static void replace_element__dispatch__isArgument(traits::true_type, iterator it, SEXP names, R_xlen_t index, const U &u)
Vector & operator=(const Vector &rhs)
Vector(const T &siz, stored_type(*gen)(U1, U2, U3), const U1 &u1, const U2 &u2, const U3 &u3, typename Rcpp::traits::enable_if< traits::is_arithmetic< T >::value, void >::type *=0)
traits::r_vector_iterator< RTYPE, StoragePolicy >::type iterator
Vector(const no_init_vector &obj)
const_iterator cend() const
traits::init_type< RTYPE >::type init_type
void fill__dispatch(traits::true_type, const U &u)
Vector(InputIterator first, InputIterator last, T n, typename Rcpp::traits::enable_if< traits::is_arithmetic< T >::value, void >::type *=0)
Vector(const Vector &other)
iterator insert(int position, const T &object)
Proxy operator()(const size_t &i)
Vector(const VectorBase< RTYPE, NA, VEC > &other)
iterator insert__impl(iterator position, const stored_type &object, traits::false_type)
void push_back(const T &object, const std::string &name)
traits::r_vector_const_proxy< RTYPE, StoragePolicy >::type const_Proxy
void fill_or_generate__impl(const T &gen, traits::true_type)
Vector(T value, typename Rcpp::traits::enable_if< traits::is_bool< T >::value &&RTYPE==LGLSXP, void >::type *=0)
iterator erase(iterator position)
iterator erase(iterator first, iterator last)
traits::r_vector_proxy< RTYPE, StoragePolicy >::type Proxy
R_xlen_t offset(const std::string &name) const
iterator erase(int first, int last)
void assign_sugar_expression(const T &x)
void push_back_name__impl(const stored_type &object, const std::string &name, traits::false_type)
void assign_object(const T &x, traits::false_type)
Vector & sort(bool decreasing=false)
static target get(const T &input)
#define RCPP_DEBUG_2(fmt, M1, M2)
#define RCPP_DEBUG_1(fmt, MSG)
#define RCPP_DEBUG_4(fmt, M1, M2, M3, M4)
#define DEMANGLE(__TYPE__)
#define RCPP_GET_NAMES(x)
T as(SEXP x, ::Rcpp::traits::r_type_primitive_tag)
integral_constant< bool, true > true_type
integral_constant< bool, false > false_type
std::ostream & operator<<(std::ostream &os, const Date d)
void NORET stop(const std::string &message)
sugar::Range< RTYPE, NA, T > range(const VectorBase< RTYPE, NA, T > &x)
SEXP Rcpp_eval(SEXP expr, SEXP env)
RObject_Impl< PreserveStorage > RObject
SEXP wrap(const Date &date)
storage_type< RTYPE >::type type
const storage_type< RTYPE >::type * type
const storage_type< RTYPE >::type & type
storage_type< RTYPE >::type * type
storage_type< RTYPE >::type & type
#define RCPP_LOOP_UNROLL(TARGET, SOURCE)