Skip to content

Commit c3e6ff7

Browse files
authored
refactor: use remove_cvref_t instead of decay_t to get exact type (#494)
`decay_t` will turn `T[]` into `T*` and function into a function pointer. It is not as accurate as `remove_cvref_t` when obtaining the original type. See https://stackoverflow.com/questions/74257533/difference-between-stddecay-and-stdremove-cvref
1 parent e5eb6e0 commit c3e6ff7

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

src/iceberg/expression/literal.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ Result<Literal> LiteralCaster::CastTo(const Literal& literal,
583583
std::size_t LiteralValueHash::operator()(const Literal::Value& value) const noexcept {
584584
return std::visit(
585585
[](const auto& v) -> std::size_t {
586-
using T = std::decay_t<decltype(v)>;
586+
using T = std::remove_cvref_t<decltype(v)>;
587587

588588
constexpr size_t kHashPrime = 0x9e3779b9;
589589

src/iceberg/manifest/manifest_reader.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ template <typename Container, typename Accessor, typename... Args>
119119
requires std::ranges::forward_range<Container>
120120
Status ParseIntegerField(const ArrowArrayView* array_view, Container& container,
121121
Accessor accessor, Args&&... args) {
122-
using T = unwrap_optional_t<std::decay_t<
122+
using T = unwrap_optional_t<std::remove_cvref_t<
123123
std::invoke_result_t<Accessor&, std::ranges::range_reference_t<Container>>>>;
124124
return ParseField(
125125
[](const ArrowArrayView* view, int64_t row_idx) {
@@ -165,11 +165,11 @@ void ParseVectorField(Transfer transfer, const ArrowArrayView* view, int64_t len
165165

166166
template <typename Container, typename Accessor>
167167
requires std::ranges::forward_range<Container> &&
168-
std::ranges::range<std::decay_t<std::invoke_result_t<
168+
std::ranges::range<std::remove_cvref_t<std::invoke_result_t<
169169
Accessor&, std::ranges::range_reference_t<Container>>>>
170170
void ParseIntegerVectorField(const ArrowArrayView* view, int64_t length,
171171
Container& container, Accessor accessor) {
172-
using T = unwrap_optional_t<std::ranges::range_value_t<std::decay_t<
172+
using T = unwrap_optional_t<std::ranges::range_value_t<std::remove_cvref_t<
173173
std::invoke_result_t<Accessor&, std::ranges::range_reference_t<Container>>>>>;
174174
return ParseVectorField(
175175
[](const ArrowArrayView* v, int64_t offset) {

src/iceberg/snapshot.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ bool SnapshotRef::Tag::Equals(const SnapshotRef::Tag& other) const {
3939
SnapshotRefType SnapshotRef::type() const noexcept {
4040
return std::visit(
4141
[&](const auto& retention) -> SnapshotRefType {
42-
using T = std::decay_t<decltype(retention)>;
42+
using T = std::remove_cvref_t<decltype(retention)>;
4343
if constexpr (std::is_same_v<T, Branch>) {
4444
return SnapshotRefType::kBranch;
4545
} else {

src/iceberg/test/matchers.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class HasValueMatcher {
140140
template <typename MatcherT>
141141
auto HasValue(MatcherT&& matcher) {
142142
return ::testing::MakePolymorphicMatcher(
143-
HasValueMatcher<std::decay_t<MatcherT>>(std::forward<MatcherT>(matcher)));
143+
HasValueMatcher<std::remove_cvref_t<MatcherT>>(std::forward<MatcherT>(matcher)));
144144
}
145145

146146
// Overload for the common case where we just want to check for presence of any value
@@ -200,15 +200,15 @@ class ResultMatcher {
200200
// Factory function for ResultMatcher for values
201201
template <typename MatcherT>
202202
auto ResultIs(MatcherT&& matcher) {
203-
return ::testing::MakePolymorphicMatcher(
204-
ResultMatcher<std::decay_t<MatcherT>>(true, std::forward<MatcherT>(matcher)));
203+
return ::testing::MakePolymorphicMatcher(ResultMatcher<std::remove_cvref_t<MatcherT>>(
204+
true, std::forward<MatcherT>(matcher)));
205205
}
206206

207207
// Factory function for ResultMatcher for errors
208208
template <typename MatcherT>
209209
auto ErrorIs(MatcherT&& matcher) {
210-
return ::testing::MakePolymorphicMatcher(
211-
ResultMatcher<std::decay_t<MatcherT>>(false, std::forward<MatcherT>(matcher)));
210+
return ::testing::MakePolymorphicMatcher(ResultMatcher<std::remove_cvref_t<MatcherT>>(
211+
false, std::forward<MatcherT>(matcher)));
212212
}
213213

214214
// Evaluate `rexpr` which should return a Result<T, Error>.

src/iceberg/test/visit_type_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ TEST_P(TypeTest, VisitTypePrintToString) {
228228

229229
TEST_P(TypeTest, VisitTypeReturnNestedTypeId) {
230230
auto visitor = [&](auto&& type) -> Result<TypeId> {
231-
using Type = std::decay_t<decltype(type)>;
231+
using Type = std::remove_cvref_t<decltype(type)>;
232232
// Check if the type is a nested type
233233
if constexpr (std::is_base_of_v<NestedType, Type>) {
234234
return type.type_id();

0 commit comments

Comments
 (0)