Skip to content

Commit 3734b5a

Browse files
authored
conformant ref qualified overloads (#393)
1 parent 00754a7 commit 3734b5a

File tree

2 files changed

+25
-51
lines changed

2 files changed

+25
-51
lines changed

src/viam/sdk/common/proto_value.cpp

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -76,49 +76,37 @@ bool ProtoValue::is_null() const {
7676
}
7777

7878
template <typename T>
79-
std::enable_if_t<std::is_scalar<T>{}, T&> ProtoValue::get_unchecked() {
79+
T& ProtoValue::get_unchecked() & {
8080
assert(this->is_a<T>());
8181
return *(this->self_.template get<T>());
8282
}
8383

84-
template <typename T>
85-
std::enable_if_t<std::is_scalar<T>{}, T> ProtoValue::get_unchecked() const {
86-
assert(this->is_a<T>());
87-
return *(this->self_.template get<T>());
88-
}
89-
90-
template bool& ProtoValue::get_unchecked<bool>();
91-
template double& ProtoValue::get_unchecked<double>();
92-
93-
template bool ProtoValue::get_unchecked<bool>() const;
94-
template double ProtoValue::get_unchecked<double>() const;
84+
template bool& ProtoValue::get_unchecked<bool>() &;
85+
template double& ProtoValue::get_unchecked<double>() &;
86+
template std::string& ProtoValue::get_unchecked<std::string>() &;
87+
template ProtoList& ProtoValue::get_unchecked<ProtoList>() &;
88+
template ProtoStruct& ProtoValue::get_unchecked<ProtoStruct>() &;
9589

9690
template <typename T>
97-
std::enable_if_t<!std::is_scalar<T>{}, T&> ProtoValue::get_unchecked() & {
91+
const T& ProtoValue::get_unchecked() const& {
9892
assert(this->is_a<T>());
9993
return *(this->self_.template get<T>());
10094
}
10195

102-
template <typename T>
103-
std::enable_if_t<!std::is_scalar<T>{}, T const&> ProtoValue::get_unchecked() const& {
104-
assert(this->is_a<T>());
105-
return *(this->self_.template get<T>());
106-
}
96+
template const bool& ProtoValue::get_unchecked<bool>() const&;
97+
template const double& ProtoValue::get_unchecked<double>() const&;
98+
template std::string const& ProtoValue::get_unchecked<std::string>() const&;
99+
template ProtoList const& ProtoValue::get_unchecked<ProtoList>() const&;
100+
template ProtoStruct const& ProtoValue::get_unchecked<ProtoStruct>() const&;
107101

108102
template <typename T>
109-
std::enable_if_t<!std::is_scalar<T>{}, T&&> ProtoValue::get_unchecked() && {
103+
T&& ProtoValue::get_unchecked() && {
110104
assert(this->is_a<T>());
111105
return std::move(*(this->self_.template get<T>()));
112106
}
113107

114-
template std::string& ProtoValue::get_unchecked<std::string>() &;
115-
template ProtoList& ProtoValue::get_unchecked<ProtoList>() &;
116-
template ProtoStruct& ProtoValue::get_unchecked<ProtoStruct>() &;
117-
118-
template std::string const& ProtoValue::get_unchecked<std::string>() const&;
119-
template ProtoList const& ProtoValue::get_unchecked<ProtoList>() const&;
120-
template ProtoStruct const& ProtoValue::get_unchecked<ProtoStruct>() const&;
121-
108+
template bool&& ProtoValue::get_unchecked<bool>() &&;
109+
template double&& ProtoValue::get_unchecked<double>() &&;
122110
template std::string&& ProtoValue::get_unchecked<std::string>() &&;
123111
template ProtoList&& ProtoValue::get_unchecked<ProtoList>() &&;
124112
template ProtoStruct&& ProtoValue::get_unchecked<ProtoStruct>() &&;

src/viam/sdk/common/proto_value.hpp

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -136,29 +136,16 @@ class ProtoValue {
136136
T const* get() const;
137137

138138
/// @brief Return a reference to the underlying T, without checking.
139-
/// @tparam T a bool or double
140139
template <typename T>
141-
std::enable_if_t<std::is_scalar<T>{}, T&> get_unchecked();
142-
143-
/// @brief Return the underlying T by value, without checking.
144-
/// @tparam T a bool or double.
145-
template <typename T>
146-
std::enable_if_t<std::is_scalar<T>{}, T> get_unchecked() const;
147-
148-
/// @brief Return a mutable reference to the underlying T, without checking
149-
/// @tparam T a std::string, ProtoList, or ProtoStruct.
150-
template <typename T>
151-
std::enable_if_t<!std::is_scalar<T>{}, T&> get_unchecked() &;
140+
T& get_unchecked() &;
152141

153142
/// @brief Return an immutable reference to the underlying T, without checking.
154-
/// @tparam T a std::string, ProtoList, or ProtoStruct.
155143
template <typename T>
156-
std::enable_if_t<!std::is_scalar<T>{}, T const&> get_unchecked() const&;
144+
const T& get_unchecked() const&;
157145

158146
/// @brief Return an rvalue reference to the underlying T, without checking.
159-
/// @tparam T a std::string, ProtoList, or ProtoStruct.
160147
template <typename T>
161-
std::enable_if_t<!std::is_scalar<T>{}, T&&> get_unchecked() &&;
148+
T&& get_unchecked() &&;
162149

163150
///@}
164151

@@ -295,22 +282,21 @@ extern template ProtoValue::ProtoValue(ProtoList) noexcept(
295282
extern template ProtoValue::ProtoValue(ProtoStruct m) noexcept(
296283
std::is_nothrow_move_constructible<ProtoStruct>{});
297284

298-
// -- Template specialization declarations of get_unchecked: POD types -- //
299-
extern template bool& ProtoValue::get_unchecked<bool>();
300-
extern template double& ProtoValue::get_unchecked<double>();
301-
302-
extern template bool ProtoValue::get_unchecked<bool>() const;
303-
extern template double ProtoValue::get_unchecked<double>() const;
304-
305-
// -- Template specialization declarations of get_unchecked: string and recursive types -- //
285+
// -- Template specialization declarations of get_unchecked -- //
286+
extern template bool& ProtoValue::get_unchecked<bool>() &;
287+
extern template double& ProtoValue::get_unchecked<double>() &;
306288
extern template std::string& ProtoValue::get_unchecked<std::string>() &;
307289
extern template ProtoList& ProtoValue::get_unchecked<ProtoList>() &;
308290
extern template ProtoStruct& ProtoValue::get_unchecked<ProtoStruct>() &;
309291

292+
extern template bool const& ProtoValue::get_unchecked<bool>() const&;
293+
extern template double const& ProtoValue::get_unchecked<double>() const&;
310294
extern template std::string const& ProtoValue::get_unchecked<std::string>() const&;
311295
extern template ProtoList const& ProtoValue::get_unchecked<ProtoList>() const&;
312296
extern template ProtoStruct const& ProtoValue::get_unchecked<ProtoStruct>() const&;
313297

298+
extern template bool&& ProtoValue::get_unchecked<bool>() &&;
299+
extern template double&& ProtoValue::get_unchecked<double>() &&;
314300
extern template std::string&& ProtoValue::get_unchecked<std::string>() &&;
315301
extern template ProtoList&& ProtoValue::get_unchecked<ProtoList>() &&;
316302
extern template ProtoStruct&& ProtoValue::get_unchecked<ProtoStruct>() &&;

0 commit comments

Comments
 (0)