Skip to content

Commit 3ac7423

Browse files
added tests for named push_* in StretchyList
1 parent 04ba7bc commit 3ac7423

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

inst/include/Rcpp/api/meat/StretchyList.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ namespace Rcpp{
3131
return *this ;
3232
}
3333

34+
template< template <class> class StoragePolicy>
35+
template< typename T>
36+
StretchyList_Impl<StoragePolicy>& StretchyList_Impl<StoragePolicy>::push_back__impl( const T& obj, traits::true_type ){
37+
Shield<SEXP> s( wrap(obj.object) ) ;
38+
SEXP tmp = Rf_cons( s, R_NilValue );
39+
Symbol tag = obj.name ;
40+
SET_TAG(tmp, tag) ;
41+
SEXP self = Storage::get__() ;
42+
SETCDR( CAR(self), tmp) ;
43+
SETCAR( self, tmp ) ;
44+
return *this ;
45+
}
46+
3447
template< template <class> class StoragePolicy>
3548
template< typename T>
3649
StretchyList_Impl<StoragePolicy>& StretchyList_Impl<StoragePolicy>::push_front__impl( const T& obj, traits::false_type){
@@ -42,6 +55,19 @@ namespace Rcpp{
4255
return *this ;
4356
}
4457

58+
template< template <class> class StoragePolicy>
59+
template< typename T>
60+
StretchyList_Impl<StoragePolicy>& StretchyList_Impl<StoragePolicy>::push_front__impl( const T& obj, traits::true_type){
61+
SEXP tmp ;
62+
SEXP self = Storage::get__() ;
63+
Shield<SEXP> s( wrap(obj.object) ) ;
64+
Symbol tag = obj.name ;
65+
tmp = Rf_cons(s, CDR(self) ) ;
66+
SET_TAG(tmp, tag );
67+
SETCDR(self, tmp) ;
68+
return *this ;
69+
}
70+
4571

4672
}
4773

inst/unitTests/cpp/misc.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,12 @@ StretchyList stretchy_list(){
142142
return out;
143143
}
144144

145+
// [[Rcpp::export]]
146+
StretchyList named_stretchy_list(){
147+
StretchyList out ;
148+
out.push_back( _["b"] = 1 ) ;
149+
out.push_front( _["a"] = "foo" ) ;
150+
out.push_back( _["c"] = 3.2 ) ;
151+
return out;
152+
}
153+

inst/unitTests/runit.misc.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,11 @@ test.StretchyList <- function(){
133133
)
134134
}
135135

136+
test.named_StretchyList <- function(){
137+
checkEquals(
138+
named_stretchy_list(),
139+
pairlist( a = "foo", b = 1L, c = 3.2 )
140+
)
141+
}
142+
136143
}

0 commit comments

Comments
 (0)