Skip to content

Commit 472f40f

Browse files
committed
+ noexcept
1 parent 91c3bd4 commit 472f40f

File tree

11 files changed

+77
-44
lines changed

11 files changed

+77
-44
lines changed

inst/include/cpp11/data_frame.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class data_frame : public list {
3535
return R_NilValue;
3636
}
3737

38-
static R_xlen_t calc_nrow(SEXP x) {
38+
// @pachadotdev: + noexcept
39+
static R_xlen_t calc_nrow(SEXP x) noexcept {
3940
auto nms = get_attrib0(x, R_RowNamesSymbol);
4041
bool has_short_rownames =
4142
(Rf_isInteger(nms) && Rf_xlength(nms) == 2 && INTEGER(nms)[0] == NA_INTEGER);
@@ -58,8 +59,8 @@ class data_frame : public list {
5859
/* Adapted from
5960
* https://github.com/wch/r-source/blob/f2a0dfab3e26fb42b8b296fcba40cbdbdbec767d/src/main/attrib.c#L198-L207
6061
*/
61-
R_xlen_t nrow() const { return calc_nrow(*this); }
62-
R_xlen_t ncol() const { return size(); }
62+
R_xlen_t nrow() const noexcept { return calc_nrow(*this); }
63+
R_xlen_t ncol() const noexcept { return size(); }
6364
};
6465

6566
namespace writable {
@@ -89,13 +90,16 @@ class data_frame : public cpp11::data_frame {
8990
using cpp11::data_frame::ncol;
9091
using cpp11::data_frame::nrow;
9192

92-
attribute_proxy<data_frame> attr(const char* name) const { return {*this, name}; }
93+
// @pachadotdev: + noexcept
94+
attribute_proxy<data_frame> attr(const char* name) const noexcept const {
95+
return {*this, name};
96+
}
9397

94-
attribute_proxy<data_frame> attr(const std::string& name) const {
98+
attribute_proxy<data_frame> attr(const std::string& name) const noexcept {
9599
return {*this, name.c_str()};
96100
}
97101

98-
attribute_proxy<data_frame> attr(SEXP name) const { return {*this, name}; }
102+
attribute_proxy<data_frame> attr(SEXP name) const noexcept { return {*this, name}; }
99103

100104
attribute_proxy<data_frame> names() const { return {*this, R_NamesSymbol}; }
101105
};

inst/include/cpp11/environment.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ class environment {
4848

4949
void remove(const char* name) { remove(safe[Rf_install](name)); }
5050

51-
R_xlen_t size() const { return Rf_xlength(env_); }
51+
// @pachadotdev: + noexcept
52+
R_xlen_t size() const noexcept { return Rf_xlength(env_); }
5253

53-
operator SEXP() const { return env_; }
54+
operator SEXP() const noexcept { return env_; }
5455
};
5556

5657
} // namespace cpp11

inst/include/cpp11/external_pointer.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212

1313
namespace cpp11 {
1414

15+
// @pachadotdev: + noexcept
1516
template <typename T>
16-
void default_deleter(T* obj) {
17+
void default_deleter(T* obj) noexcept{
1718
delete obj;
1819
}
1920

@@ -33,12 +34,13 @@ class external_pointer {
3334
return data;
3435
}
3536

36-
static void r_deleter(SEXP p) {
37+
// @pachadotdev: + noexcept
38+
static void r_deleter(SEXP p) noexcept {
3739
if (detail::r_typeof(p) != EXTPTRSXP) return;
3840

3941
T* ptr = static_cast<T*>(R_ExternalPtrAddr(p));
4042

41-
if (ptr == NULL) {
43+
if (ptr == nullptr) {
4244
return;
4345
}
4446

inst/include/cpp11/function.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <string.h> // for strcmp
3+
#include <cstring> // for std::strcmp (@pachadotdev use std qualifiers)
44

55
#include <cstdio> // for snprintf
66
#include <string> // for string, basic_string

inst/include/cpp11/matrix.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,10 @@ class matrix : public matrix_slices<S> {
184184

185185
SEXP data() const { return vector_.data(); }
186186

187-
R_xlen_t size() const { return vector_.size(); }
187+
// @pachadotdev: + noexcept
188+
R_xlen_t size() const noexcept { return vector_.size(); }
188189

189-
operator SEXP() const { return SEXP(vector_); }
190+
operator SEXP() const noexcept { return SEXP(vector_); }
190191

191192
// operator sexp() { return sexp(vector_); }
192193

inst/include/cpp11/named_arg.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
namespace cpp11 {
1212
class named_arg {
1313
public:
14-
explicit named_arg(const char* name) : name_(name), value_(R_NilValue) {}
14+
// @pachadotdev: + noexcept
15+
explicit named_arg(const char* name) noexcept : name_(name), value_(R_NilValue) {}
1516
named_arg& operator=(std::initializer_list<int> il) {
1617
value_ = as_sexp(il);
1718
return *this;
@@ -39,7 +40,10 @@ class named_arg {
3940

4041
namespace literals {
4142

42-
inline named_arg operator""_nm(const char* name, std::size_t) { return named_arg(name); }
43+
// @pachadotdev: + noexcept
44+
inline named_arg operator""_nm(const char* name, std::size_t) noexcept {
45+
return named_arg(name);
46+
}
4347

4448
} // namespace literals
4549

inst/include/cpp11/r_bool.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ enable_if_r_bool<T, SEXP> as_sexp(T from) {
6666
return res;
6767
}
6868

69+
// @pachadotdev: + noexcept
6970
template <>
70-
inline r_bool na() {
71+
inline r_bool na() noexcept {
7172
return NA_LOGICAL;
7273
}
7374

inst/include/cpp11/r_vector.hpp

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ class r_vector {
6565
r_vector& operator=(const r_vector& rhs);
6666
r_vector& operator=(r_vector&& rhs);
6767

68-
operator SEXP() const;
69-
operator sexp() const;
68+
// @pachadotdev: + noexcept
69+
operator SEXP() noexcept const;
70+
operator sexp() noexcept const;
7071

7172
#ifdef LONG_VECTOR_SUPPORT
7273
T operator[](const int pos) const;
@@ -85,20 +86,22 @@ class r_vector {
8586
bool contains(const r_string& name) const;
8687
bool is_altrep() const;
8788
bool named() const;
88-
R_xlen_t size() const;
89-
bool empty() const;
90-
SEXP data() const;
89+
// @pachadotdev: + noexcept
90+
R_xlen_t size() noexcept const;
91+
bool empty() no except const;
92+
SEXP data() noexcept const;
9193

9294
const sexp attr(const char* name) const;
9395
const sexp attr(const std::string& name) const;
9496
const sexp attr(SEXP name) const;
9597

9698
r_vector<r_string> names() const;
9799

98-
const_iterator begin() const;
99-
const_iterator end() const;
100-
const_iterator cbegin() const;
101-
const_iterator cend() const;
100+
// @pachadotdev: + noexcept
101+
const_iterator begin() noexcept const;
102+
const_iterator end() noexcept const;
103+
const_iterator cbegin() noexcept const;
104+
const_iterator cend() noexcept const;
102105
const_iterator find(const r_string& name) const;
103106

104107
class const_iterator {
@@ -448,13 +451,15 @@ inline r_vector<T>& r_vector<T>::operator=(r_vector&& rhs) {
448451
return *this;
449452
}
450453

454+
// @pachadotdev: + noexcept
451455
template <typename T>
452-
inline r_vector<T>::operator SEXP() const {
456+
inline r_vector<T>::operator SEXP() const noexcept {
453457
return data_;
454458
}
455459

460+
// @pachadotdev: + noexcept
456461
template <typename T>
457-
inline r_vector<T>::operator sexp() const {
462+
inline r_vector<T>::operator sexp() const noexcept {
458463
return data_;
459464
}
460465

@@ -636,23 +641,27 @@ inline SEXP r_vector<T>::valid_length(SEXP x, R_xlen_t n) {
636641
throw std::length_error(message);
637642
}
638643

644+
// @pachadotdev: + noexcept
639645
template <typename T>
640-
inline typename r_vector<T>::const_iterator r_vector<T>::begin() const {
646+
inline typename r_vector<T>::const_iterator r_vector<T>::begin() const noexcept {
641647
return const_iterator(this, 0);
642648
}
643649

650+
// @pachadotdev: + noexcept
644651
template <typename T>
645-
inline typename r_vector<T>::const_iterator r_vector<T>::end() const {
652+
inline typename r_vector<T>::const_iterator r_vector<T>::end() const noexcept{
646653
return const_iterator(this, length_);
647654
}
648655

656+
// @pachadotdev: + noexcept
649657
template <typename T>
650-
inline typename r_vector<T>::const_iterator r_vector<T>::cbegin() const {
658+
inline typename r_vector<T>::const_iterator r_vector<T>::cbegin() const noexcept {
651659
return const_iterator(this, 0);
652660
}
653661

662+
// @pachadotdev: + noexcept
654663
template <typename T>
655-
inline typename r_vector<T>::const_iterator r_vector<T>::cend() const {
664+
inline typename r_vector<T>::const_iterator r_vector<T>::cend() const noexcept {
656665
return const_iterator(this, length_);
657666
}
658667

@@ -1070,8 +1079,9 @@ inline void r_vector<T>::push_back(T value) {
10701079
++length_;
10711080
}
10721081

1082+
// @pachadotdev: + noexcept
10731083
template <typename T>
1074-
inline void r_vector<T>::pop_back() {
1084+
inline void r_vector<T>::pop_back() noexcept {
10751085
--length_;
10761086
}
10771087

@@ -1128,7 +1138,7 @@ inline typename r_vector<T>::iterator r_vector<T>::erase(R_xlen_t pos) {
11281138
}
11291139

11301140
template <typename T>
1131-
inline void r_vector<T>::clear() {
1141+
inline void r_vector<T>::clear() noexcept {
11321142
length_ = 0;
11331143
}
11341144

inst/include/cpp11/raws.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ typedef r_vector<uint8_t> raws;
6767

6868
namespace writable {
6969

70+
// @pachadotdev: + noexcept
7071
template <>
7172
inline void r_vector<uint8_t>::set_elt(SEXP x, R_xlen_t i,
72-
typename r_vector::underlying_type value) {
73+
typename r_vector::underlying_type value) noexcept {
7374
// NOPROTECT: Likely too costly to unwind protect every set elt
7475
#if R_VERSION >= R_Version(4, 2, 0)
7576
SET_RAW_ELT(x, i, value);

inst/include/cpp11/sexp.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,13 @@ class sexp {
6868
operator SEXP() const noexcept { return data_; }
6969
SEXP data() const noexcept { return data_; }
7070

71+
// @pachadotdev: + noexcept
7172
/// DEPRECATED: Do not use this, it will be removed soon.
72-
operator double() const { return REAL_ELT(data_, 0); }
73+
operator double() const noexcept { return REAL_ELT(data_, 0); }
7374
/// DEPRECATED: Do not use this, it will be removed soon.
74-
operator size_t() const { return REAL_ELT(data_, 0); }
75+
operator size_t() const noexcept { returnv REAL_ELT(data_, 0); }
7576
/// DEPRECATED: Do not use this, it will be removed soon.
76-
operator bool() const { return LOGICAL_ELT(data_, 0); }
77+
operator bool() const noexcept { return LOGICAL_ELT(data_, 0); }
7778
};
7879

7980
} // namespace cpp11

0 commit comments

Comments
 (0)