Skip to content

Commit db8f2dd

Browse files
laramielcopybara-github
authored andcommitted
Fixes for C++23
std::result_of is removed. GetLValue appears to be move-ing x. P2266R3 Fixes: #240 PiperOrigin-RevId: 783643789 Change-Id: I5e6fd58b2c88c85c5b86f0417df8dc2b956dfdae
1 parent 96f1270 commit db8f2dd

File tree

4 files changed

+59
-55
lines changed

4 files changed

+59
-55
lines changed

tensorstore/internal/BUILD

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,10 @@ tensorstore_cc_test(
16321632
tensorstore_cc_library(
16331633
name = "compare",
16341634
hdrs = ["compare.h"],
1635-
deps = ["@abseil-cpp//absl/types:compare"],
1635+
deps = [
1636+
"@abseil-cpp//absl/meta:type_traits",
1637+
"@abseil-cpp//absl/types:compare",
1638+
],
16361639
)
16371640

16381641
tensorstore_cc_test(

tensorstore/internal/cache/cache.h

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -158,57 +158,6 @@ class CachePool : private internal_cache::CachePoolImpl {
158158
friend class internal_cache::Access;
159159
};
160160

161-
/// Returns a cache of type `CacheType` for the specified `cache_key`.
162-
///
163-
/// If such a cache does not already exist, or `cache_key` is empty,
164-
/// `make_cache()` is called to obtain a new such cache.
165-
///
166-
/// \tparam CacheType Must be a class that inherits from `Cache`, or defines a
167-
/// `Cache& cache()` method.
168-
/// \param pool Cache pool, may be `nullptr` to indicate that caching is
169-
/// disabled.
170-
/// \param type_info Additional key used in looking up the cache. Has no effect
171-
/// if `cache_key` is the empty string or `pool` is `nullptr`. Set to
172-
/// `typeid(CacheType)` when calling `GetCache`, but can be any arbitrary
173-
/// `std::type_info` object.
174-
/// \param cache_key Specifies the cache key.
175-
/// \param make_cache Nullary function that returns an
176-
/// `std::unique_ptr<CacheType>`, where `CacheType` as a type that inherits
177-
/// from `Cache` or defines a `Cache& cache()` method. A `nullptr` may be
178-
/// returned to indicate an error creating the cache (any additional error
179-
/// information must be communicated via some separate out-of-band channel).
180-
template <typename CacheType, typename MakeCache>
181-
CachePtr<CacheType> GetCacheWithExplicitTypeInfo(
182-
CachePool* pool, const std::type_info& type_info,
183-
std::string_view cache_key, MakeCache&& make_cache) {
184-
auto cache = internal_cache::GetCacheInternal(
185-
internal_cache::Access::StaticCast<internal_cache::CachePoolImpl>(pool),
186-
type_info, cache_key, [&]() -> std::unique_ptr<internal::Cache> {
187-
std::unique_ptr<CacheType> cache = make_cache();
188-
if (!cache) return nullptr;
189-
void* user_ptr = cache.get();
190-
auto base_ptr = std::unique_ptr<internal::Cache>(
191-
&internal_cache::GetCacheObject(cache.release()));
192-
internal_cache::Access::StaticCast<internal_cache::CacheImpl>(
193-
base_ptr.get())
194-
->user_ptr_ = user_ptr;
195-
return base_ptr;
196-
});
197-
if (!cache) return nullptr;
198-
return CachePtr<CacheType>(
199-
static_cast<CacheType*>(
200-
internal_cache::Access::StaticCast<internal_cache::CacheImpl>(
201-
cache.release())
202-
->user_ptr_),
203-
internal::adopt_object_ref);
204-
}
205-
template <typename CacheType, typename MakeCache>
206-
CachePtr<CacheType> GetCache(CachePool* pool, std::string_view cache_key,
207-
MakeCache&& make_cache) {
208-
return GetCacheWithExplicitTypeInfo<CacheType>(
209-
pool, typeid(CacheType), cache_key, std::forward<MakeCache>(make_cache));
210-
}
211-
212161
/// Pointer to a cache entry that prevents it from being evicted due to memory
213162
/// pressure, but still permits it to be destroyed if its parent cache is
214163
/// destroyed.
@@ -373,6 +322,57 @@ class Cache : private internal_cache::CacheImpl {
373322
friend class internal_cache::Access;
374323
};
375324

325+
/// Returns a cache of type `CacheType` for the specified `cache_key`.
326+
///
327+
/// If such a cache does not already exist, or `cache_key` is empty,
328+
/// `make_cache()` is called to obtain a new such cache.
329+
///
330+
/// \tparam CacheType Must be a class that inherits from `Cache`, or defines a
331+
/// `Cache& cache()` method.
332+
/// \param pool Cache pool, may be `nullptr` to indicate that caching is
333+
/// disabled.
334+
/// \param type_info Additional key used in looking up the cache. Has no effect
335+
/// if `cache_key` is the empty string or `pool` is `nullptr`. Set to
336+
/// `typeid(CacheType)` when calling `GetCache`, but can be any arbitrary
337+
/// `std::type_info` object.
338+
/// \param cache_key Specifies the cache key.
339+
/// \param make_cache Nullary function that returns an
340+
/// `std::unique_ptr<CacheType>`, where `CacheType` as a type that inherits
341+
/// from `Cache` or defines a `Cache& cache()` method. A `nullptr` may be
342+
/// returned to indicate an error creating the cache (any additional error
343+
/// information must be communicated via some separate out-of-band channel).
344+
template <typename CacheType, typename MakeCache>
345+
CachePtr<CacheType> GetCacheWithExplicitTypeInfo(
346+
CachePool* pool, const std::type_info& type_info,
347+
std::string_view cache_key, MakeCache&& make_cache) {
348+
auto cache = internal_cache::GetCacheInternal(
349+
internal_cache::Access::StaticCast<internal_cache::CachePoolImpl>(pool),
350+
type_info, cache_key, [&]() -> std::unique_ptr<internal::Cache> {
351+
std::unique_ptr<CacheType> cache = make_cache();
352+
if (!cache) return nullptr;
353+
void* user_ptr = cache.get();
354+
auto base_ptr = std::unique_ptr<internal::Cache>(
355+
&internal_cache::GetCacheObject(cache.release()));
356+
internal_cache::Access::StaticCast<internal_cache::CacheImpl>(
357+
base_ptr.get())
358+
->user_ptr_ = user_ptr;
359+
return base_ptr;
360+
});
361+
if (!cache) return nullptr;
362+
return CachePtr<CacheType>(
363+
static_cast<CacheType*>(
364+
internal_cache::Access::StaticCast<internal_cache::CacheImpl>(
365+
cache.release())
366+
->user_ptr_),
367+
internal::adopt_object_ref);
368+
}
369+
template <typename CacheType, typename MakeCache>
370+
CachePtr<CacheType> GetCache(CachePool* pool, std::string_view cache_key,
371+
MakeCache&& make_cache) {
372+
return GetCacheWithExplicitTypeInfo<CacheType>(
373+
pool, typeid(CacheType), cache_key, std::forward<MakeCache>(make_cache));
374+
}
375+
376376
/// Returns a reference to the cache that contains `entry`. The reference
377377
/// lifetime is tied to the lifetime of `entry`, but the lifetime of the cache
378378
/// may be extended by creating a CachePtr.

tensorstore/internal/compare.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include <type_traits>
1919

20+
#include "absl/meta/type_traits.h"
2021
#include "absl/types/compare.h"
2122

2223
namespace tensorstore {
@@ -42,7 +43,7 @@ constexpr inline absl::weak_ordering CompareResultAsWeakOrdering(
4243
// integer value, as in `std::string_view::compare`.
4344
template <
4445
typename Compare, typename K, typename LK,
45-
std::enable_if_t<!std::is_same<bool, std::result_of_t<Compare(
46+
std::enable_if_t<!std::is_same<bool, absl::result_of_t<Compare(
4647
const K &, const LK &)>>::value,
4748
int> = 0>
4849
constexpr absl::weak_ordering DoThreeWayComparison(const Compare &compare,
@@ -52,7 +53,7 @@ constexpr absl::weak_ordering DoThreeWayComparison(const Compare &compare,
5253

5354
template <
5455
typename Compare, typename K, typename LK,
55-
std::enable_if_t<std::is_same<bool, std::result_of_t<Compare(
56+
std::enable_if_t<std::is_same<bool, absl::result_of_t<Compare(
5657
const K &, const LK &)>>::value,
5758
int> = 0>
5859
constexpr absl::weak_ordering DoThreeWayComparison(const Compare &compare,

tensorstore/internal/meta/type_traits.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ using CopyQualifiers =
203203
/// for specifying default argument values.
204204
template <typename T>
205205
inline T& GetLValue(T&& x) {
206-
return x;
206+
return static_cast<T&>(x);
207207
}
208208

209209
/// Type alias that evaluates to its first argument. Additional type arguments,

0 commit comments

Comments
 (0)