Skip to content

Commit ad799af

Browse files
committed
std::string_view support in Rcpp::wrap()
1 parent 6dfb816 commit ad799af

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

inst/include/Rcpp/internal/wrap.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ namespace Rcpp {
6666
return make_charsexp__impl__cstring(st.c_str());
6767
}
6868

69+
#if __cplusplus >= 201703L
70+
inline SEXP make_charsexp__impl__cstring(std::string_view st) {
71+
return Rf_mkCharLen(st.data(), st.size());
72+
}
73+
#endif
74+
6975
template <typename T>
7076
inline SEXP make_charsexp__impl(const T& s, Rcpp::traits::true_type) {
7177
return make_charsexp__impl__wstring(s);

inst/include/Rcpp/traits/r_type_traits.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ template<> struct r_type_traits<Rcomplex>{ typedef r_type_primitive_tag r_catego
141141
template<> struct r_type_traits<bool>{ typedef r_type_primitive_tag r_category ; } ;
142142
template<> struct r_type_traits<std::string>{ typedef r_type_string_tag r_category ; } ;
143143
template<> struct r_type_traits<std::wstring>{ typedef r_type_string_tag r_category ; } ;
144+
#if __cplusplus >= 201703L
145+
template<> struct r_type_traits<std::string_view>{ typedef r_type_string_tag r_category ; } ;
146+
#endif
144147
template<> struct r_type_traits<char>{ typedef r_type_string_tag r_category ; } ;
145148
template<> struct r_type_traits<wchar_t>{ typedef r_type_string_tag r_category ; } ;
146149

inst/include/Rcpp/traits/wrap_type_traits.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ template <> struct wrap_type_traits<unsigned int> { typedef wrap_type_primitive_
8282
template <> struct wrap_type_traits<bool> { typedef wrap_type_primitive_tag wrap_category; } ;
8383
template <> struct wrap_type_traits<std::string> { typedef wrap_type_primitive_tag wrap_category; } ;
8484
template <> struct wrap_type_traits<std::wstring> { typedef wrap_type_primitive_tag wrap_category; } ;
85+
#if __cplusplus >= 201703L
86+
template <> struct wrap_type_traits<std::string_view> { typedef wrap_type_primitive_tag wrap_category; } ;
87+
#endif
8588
template <> struct wrap_type_traits<Rcpp::String> { typedef wrap_type_primitive_tag wrap_category; } ;
8689
template <> struct wrap_type_traits<char> { typedef wrap_type_primitive_tag wrap_category; } ;
8790
template <> struct wrap_type_traits<wchar_t> { typedef wrap_type_primitive_tag wrap_category; } ;

inst/include/RcppCommon.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ namespace Rcpp {
5454
#include <iomanip>
5555
#include <sstream>
5656
#include <string>
57+
#if __cplusplus >= 201703L
58+
#include <string_view>
59+
#endif
5760
#include <list>
5861
#include <map>
5962
#include <set>

0 commit comments

Comments
 (0)