-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcreate.h
More file actions
72 lines (57 loc) · 2.26 KB
/
create.h
File metadata and controls
72 lines (57 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef Rcpp__vector_create_h
#define Rcpp__vector_create_h
namespace Rcpp{
template <int RTYPE, typename... Args>
class Create {
typedef typename traits::r_vector_element_converter<RTYPE>::type converter_type ;
typedef Vector<RTYPE> Vec ;
public:
Create( Args... args ) : data( (int)sizeof...(Args) ) {
set_value( traits::number_to_type<sizeof...(Args)>(), 0, args...) ;
}
operator Vec(){ return data ; }
private:
template <typename T, typename... Pack>
inline void set_value( traits::number_to_type<sizeof...(Pack) + 1>, int i, const T& obj, const Pack&... pack ){
data[i] = converter_type::get(obj) ;
set_value( typename traits::number_to_type< sizeof...(Pack) >() , i+1, pack... ) ;
}
inline void set_value( traits::number_to_type<0>, int /* i */ ){}
Vec data ;
} ;
template <int RTYPE, typename... Args>
class CreateWithNames {
typedef typename traits::r_vector_element_converter<RTYPE>::type converter_type ;
typedef Vector<RTYPE> Vec ;
public:
CreateWithNames( Args... args ) :
data( (int)sizeof...(Args)),
names( (int)sizeof...(Args))
{
if( sizeof...(Args) ){
set_value( traits::number_to_type<sizeof...(Args)>(), 0, args...) ;
}
data.names() = names ;
}
operator Vec(){ return data ; }
private:
template <typename T, typename... Pack>
inline void set_value( traits::number_to_type<sizeof...(Pack) + 1>, int i, const T& obj, const Pack&... pack ){
data[i] = converter_type::get(obj) ;
names[i] = Rf_mkChar( internal::get_object_name(obj) ) ;
set_value( typename traits::number_to_type< sizeof...(Pack) >() , i+1, pack... ) ;
}
inline void set_value( traits::number_to_type<0>, int /* i */){}
Vec data ;
CharacterVector names ;
} ;
template <int RTYPE, typename... Args>
struct create_type {
typedef typename std::conditional<
traits::any_named<Args...>::type::value,
CreateWithNames<RTYPE, Args...>,
Create<RTYPE, Args...>
>::type type ;
} ;
}
#endif