Skip to content

Commit 000c1a6

Browse files
committed
alternate strategy
1 parent c07fced commit 000c1a6

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2014-09-14 Kevin Ushey <kevinushey@gmail.com>
2+
3+
* inst/include/Rcpp/vector/Vector.h: Alternate strategy using SFINAE
4+
* inst/include/Rcpp/traits/traits.h: Idem
5+
* inst/include/Rcpp/traits/enable_if.h: Idem
6+
17
2014-09-13 Kevin Ushey <kevinushey@gmail.com>
28

39
* inst/include/Rcpp/vector/Vector.h: Allow logical vectors to be created
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef RCPP_TRAITS_ENABLE_IF_H
2+
#define RCPP_TRAITS_ENABLE_IF_H
3+
4+
namespace Rcpp {
5+
namespace traits {
6+
7+
template <bool B, typename T = void>
8+
struct enable_if {};
9+
10+
template <typename T>
11+
struct enable_if<true, T> {
12+
typedef T type;
13+
};
14+
15+
}
16+
}
17+
18+
#endif

inst/include/Rcpp/traits/traits.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct int2type { enum { value = I }; };
3737

3838
#include <Rcpp/traits/integral_constant.h>
3939
#include <Rcpp/traits/same_type.h>
40+
#include <Rcpp/traits/enable_if.h>
4041
#include <Rcpp/traits/is_wide_string.h>
4142
#include <Rcpp/traits/char_type.h>
4243
#include <Rcpp/traits/named_object.h>

inst/include/Rcpp/vector/Vector.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ class Vector :
8989
fill( u ) ;
9090
}
9191

92-
// constructor for CharacterVector()
92+
// constructor for CharacterVector()
9393
Vector( const std::string& st ){
9494
RCPP_DEBUG_2( "Vector<%d>( const std::string& = %s )", RTYPE, st.c_str() )
9595
Storage::set__( internal::vector_from_string<RTYPE>(st) ) ;
9696
}
9797

98-
// constructor for CharacterVector()
98+
// constructor for CharacterVector()
9999
Vector( const char* st ) {
100100
RCPP_DEBUG_2( "Vector<%d>( const char* = %s )", RTYPE, st )
101101
Storage::set__(internal::vector_from_string<RTYPE>(st) ) ;
@@ -119,8 +119,9 @@ class Vector :
119119
}
120120
}
121121

122-
template <typename T = typename Rcpp::traits::if_<RTYPE == LGLSXP, bool, void>::type>
123-
Vector(bool value) {
122+
// Enable construction from bool for LogicalVectors
123+
template <int T = RTYPE>
124+
Vector(bool value, typename Rcpp::traits::enable_if<T == LGLSXP, void>::type* = 0) {
124125
Storage::set__(Rf_allocVector(RTYPE, 1));
125126
fill(value);
126127
}

0 commit comments

Comments
 (0)