From 52ea781f4fb0c4537f4d097da683d9a894a48d48 Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Tue, 18 Aug 2020 12:07:11 +0200 Subject: [PATCH 01/11] disbable smart pointers (shared, unique, weak) from as_cpp<'constructible from SEXP'> closes #96 --- inst/include/cpp11/as.hpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/inst/include/cpp11/as.hpp b/inst/include/cpp11/as.hpp index aa41b13b..587741b9 100644 --- a/inst/include/cpp11/as.hpp +++ b/inst/include/cpp11/as.hpp @@ -16,6 +16,18 @@ using enable_if_t = typename std::enable_if::type; template using decay_t = typename std::decay::type; +template +struct is_smart_ptr : std::false_type {};; + +template +struct is_smart_ptr> : std::true_type{}; + +template +struct is_smart_ptr> : std::true_type{}; + +template +struct is_smart_ptr> : std::true_type{}; + template using enable_if_constructible_from_sexp = enable_if_t::value && std::is_constructible::value, R>; @@ -62,7 +74,7 @@ inline bool is_convertable_without_loss_to_integer(double value) { return std::modf(value, &int_part) == 0.0; } -template +template ::value>> enable_if_constructible_from_sexp as_cpp(SEXP from) { return T(from); } From 3a5066f347b4e4be606e604612dbc69be8fbdc5e Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Tue, 18 Aug 2020 12:12:45 +0200 Subject: [PATCH 02/11] ;;->; --- inst/include/cpp11/as.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/include/cpp11/as.hpp b/inst/include/cpp11/as.hpp index 587741b9..c1edca54 100644 --- a/inst/include/cpp11/as.hpp +++ b/inst/include/cpp11/as.hpp @@ -17,7 +17,7 @@ template using decay_t = typename std::decay::type; template -struct is_smart_ptr : std::false_type {};; +struct is_smart_ptr : std::false_type {}; template struct is_smart_ptr> : std::true_type{}; From 157acf37119d5873a954e79e7af8bed8a5fd96db Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Tue, 18 Aug 2020 12:18:13 +0200 Subject: [PATCH 03/11] space --- inst/include/cpp11/as.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inst/include/cpp11/as.hpp b/inst/include/cpp11/as.hpp index c1edca54..fbcd34b4 100644 --- a/inst/include/cpp11/as.hpp +++ b/inst/include/cpp11/as.hpp @@ -20,13 +20,13 @@ template struct is_smart_ptr : std::false_type {}; template -struct is_smart_ptr> : std::true_type{}; +struct is_smart_ptr> : std::true_type {}; template -struct is_smart_ptr> : std::true_type{}; +struct is_smart_ptr> : std::true_type {}; template -struct is_smart_ptr> : std::true_type{}; +struct is_smart_ptr> : std::true_type {}; template using enable_if_constructible_from_sexp = From 320e23055598770f57a26118ef3cecfa42865900 Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Tue, 18 Aug 2020 12:27:20 +0200 Subject: [PATCH 04/11] include --- inst/include/cpp11/as.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/inst/include/cpp11/as.hpp b/inst/include/cpp11/as.hpp index fbcd34b4..8e801df9 100644 --- a/inst/include/cpp11/as.hpp +++ b/inst/include/cpp11/as.hpp @@ -1,9 +1,10 @@ #pragma once -#include // for modf -#include // for initializer_list -#include // for string, basic_string -#include // for decay, enable_if, is_same, is_convertible +#include // for modf +#include // for initializer_list +#include // for string, basic_string +#include // for decay, enable_if, is_same, is_convertible +#include // for std::shared_ptr, std::weak_ptr, std::unique_ptr #include "cpp11/R.hpp" // for SEXP, SEXPREC, Rf_xlength, R_xlen_t #include "cpp11/protect.hpp" // for stop, protect, safe, protect::function From ab30faa54b4beeaf6d2fe4721260aaa16ca592e5 Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Tue, 18 Aug 2020 13:23:59 +0200 Subject: [PATCH 05/11] format_check --- inst/include/cpp11/as.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/inst/include/cpp11/as.hpp b/inst/include/cpp11/as.hpp index 8e801df9..ed4f532a 100644 --- a/inst/include/cpp11/as.hpp +++ b/inst/include/cpp11/as.hpp @@ -1,10 +1,10 @@ #pragma once -#include // for modf -#include // for initializer_list -#include // for string, basic_string -#include // for decay, enable_if, is_same, is_convertible -#include // for std::shared_ptr, std::weak_ptr, std::unique_ptr +#include // for modf +#include // for initializer_list +#include // for string, basic_string +#include // for decay, enable_if, is_same, is_convertible +#include // for std::shared_ptr, std::weak_ptr, std::unique_ptr #include "cpp11/R.hpp" // for SEXP, SEXPREC, Rf_xlength, R_xlen_t #include "cpp11/protect.hpp" // for stop, protect, safe, protect::function From 32eeffb6c5bf88767c0c2d3b1239f47a633ba401 Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Tue, 18 Aug 2020 14:27:17 +0200 Subject: [PATCH 06/11] format check --- inst/include/cpp11/as.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/inst/include/cpp11/as.hpp b/inst/include/cpp11/as.hpp index ed4f532a..20bf0111 100644 --- a/inst/include/cpp11/as.hpp +++ b/inst/include/cpp11/as.hpp @@ -1,10 +1,10 @@ #pragma once -#include // for modf -#include // for initializer_list -#include // for string, basic_string -#include // for decay, enable_if, is_same, is_convertible -#include // for std::shared_ptr, std::weak_ptr, std::unique_ptr +#include // for modf +#include // for initializer_list +#include // for string, basic_string +#include // for decay, enable_if, is_same, is_convertible +#include // for std::shared_ptr, std::weak_ptr, std::unique_ptr #include "cpp11/R.hpp" // for SEXP, SEXPREC, Rf_xlength, R_xlen_t #include "cpp11/protect.hpp" // for stop, protect, safe, protect::function From 8d7d17e9bef95925e0435adf16bee68b98dbd3ef Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Tue, 18 Aug 2020 15:24:42 +0200 Subject: [PATCH 07/11] format check --- inst/include/cpp11/as.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/include/cpp11/as.hpp b/inst/include/cpp11/as.hpp index 20bf0111..8e79bba9 100644 --- a/inst/include/cpp11/as.hpp +++ b/inst/include/cpp11/as.hpp @@ -2,9 +2,9 @@ #include // for modf #include // for initializer_list +#include // for std::shared_ptr, std::weak_ptr, std::unique_ptr #include // for string, basic_string #include // for decay, enable_if, is_same, is_convertible -#include // for std::shared_ptr, std::weak_ptr, std::unique_ptr #include "cpp11/R.hpp" // for SEXP, SEXPREC, Rf_xlength, R_xlen_t #include "cpp11/protect.hpp" // for stop, protect, safe, protect::function From 4e0adb15cb79e48d36cd5ee122e6d0ce2c234f77 Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Tue, 18 Aug 2020 15:39:10 +0200 Subject: [PATCH 08/11] move !is_smart_ptr<> inside enable_if_constructible_from_sexp and comment about it being a workaround. Thanks @bkietz --- inst/include/cpp11/as.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/inst/include/cpp11/as.hpp b/inst/include/cpp11/as.hpp index 8e79bba9..89037d0e 100644 --- a/inst/include/cpp11/as.hpp +++ b/inst/include/cpp11/as.hpp @@ -31,7 +31,11 @@ struct is_smart_ptr> : std::true_type {}; template using enable_if_constructible_from_sexp = - enable_if_t::value && std::is_constructible::value, R>; + enable_if_t< + !is_smart_ptr::value && // workaround for gcc 4.8 + std::is_class::value && std::is_constructible::value, + R + >; template using enable_if_is_sexp = enable_if_t::value, R>; @@ -75,7 +79,7 @@ inline bool is_convertable_without_loss_to_integer(double value) { return std::modf(value, &int_part) == 0.0; } -template ::value>> +template enable_if_constructible_from_sexp as_cpp(SEXP from) { return T(from); } From d33954bdab884b573151f0f6b1fd1c14ce5d1ea6 Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Tue, 18 Aug 2020 15:42:13 +0200 Subject: [PATCH 09/11] format check ? --- inst/include/cpp11/as.hpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/inst/include/cpp11/as.hpp b/inst/include/cpp11/as.hpp index 89037d0e..82e64384 100644 --- a/inst/include/cpp11/as.hpp +++ b/inst/include/cpp11/as.hpp @@ -31,11 +31,9 @@ struct is_smart_ptr> : std::true_type {}; template using enable_if_constructible_from_sexp = - enable_if_t< - !is_smart_ptr::value && // workaround for gcc 4.8 - std::is_class::value && std::is_constructible::value, - R - >; + enable_if_t::value && // workaround for gcc 4.8 + std::is_class::value && std::is_constructible::value, + R>; template using enable_if_is_sexp = enable_if_t::value, R>; From d74e532a194dd10bdc1cdcdd1433440bd142d5dc Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Tue, 18 Aug 2020 15:52:20 +0200 Subject: [PATCH 10/11] format check ?? --- inst/include/cpp11/as.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/include/cpp11/as.hpp b/inst/include/cpp11/as.hpp index 82e64384..df71246f 100644 --- a/inst/include/cpp11/as.hpp +++ b/inst/include/cpp11/as.hpp @@ -32,7 +32,7 @@ struct is_smart_ptr> : std::true_type {}; template using enable_if_constructible_from_sexp = enable_if_t::value && // workaround for gcc 4.8 - std::is_class::value && std::is_constructible::value, + std::is_class::value && std::is_constructible::value, R>; template From 67016eb683ea8f7c3840950487f9d9a68896b2d6 Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Tue, 18 Aug 2020 16:02:51 +0200 Subject: [PATCH 11/11] format check ??? --- inst/include/cpp11/as.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/include/cpp11/as.hpp b/inst/include/cpp11/as.hpp index df71246f..a02c7588 100644 --- a/inst/include/cpp11/as.hpp +++ b/inst/include/cpp11/as.hpp @@ -31,7 +31,7 @@ struct is_smart_ptr> : std::true_type {}; template using enable_if_constructible_from_sexp = - enable_if_t::value && // workaround for gcc 4.8 + enable_if_t::value && // workaround for gcc 4.8 std::is_class::value && std::is_constructible::value, R>;