Coverage Report

Created: 2026-05-27 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/internal/to_address.h
Line
Count
Source
1
// Copyright 2024 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef THIRD_PARTY_CEL_CPP_INTERNAL_TO_ADDRESS_H_
16
#define THIRD_PARTY_CEL_CPP_INTERNAL_TO_ADDRESS_H_
17
18
#include <memory>
19
#include <type_traits>
20
#include <utility>
21
22
#include "absl/base/attributes.h"
23
#include "absl/meta/type_traits.h"
24
25
namespace cel::internal {
26
27
// -----------------------------------------------------------------------------
28
// Function Template: to_address()
29
// -----------------------------------------------------------------------------
30
//
31
// Backport of std::to_address introduced in C++20. Enables obtaining the
32
// address of an object regardless of whether the pointer is raw or fancy.
33
#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
34
using std::to_address;
35
#else
36
template <typename T>
37
0
constexpr T* to_address(T* ptr) noexcept {
38
0
  static_assert(!std::is_function<T>::value, "T must not be a function");
39
0
  return ptr;
40
0
}
41
42
template <typename T, typename = void>
43
struct PointerTraitsToAddress {
44
  static constexpr auto Dispatch(
45
      const T& p ABSL_ATTRIBUTE_LIFETIME_BOUND) noexcept {
46
    return internal::to_address(p.operator->());
47
  }
48
};
49
50
template <typename T>
51
struct PointerTraitsToAddress<
52
    T, std::void_t<decltype(std::pointer_traits<T>::to_address(
53
           std::declval<const T&>()))> > {
54
  static constexpr auto Dispatch(
55
0
      const T& p ABSL_ATTRIBUTE_LIFETIME_BOUND) noexcept {
56
0
    return std::pointer_traits<T>::to_address(p);
57
0
  }
Unexecuted instantiation: cel::internal::PointerTraitsToAddress<cel::ParsedMessageValue, void>::Dispatch(cel::ParsedMessageValue const&)
Unexecuted instantiation: cel::internal::PointerTraitsToAddress<cel::ParsedJsonListValue, void>::Dispatch(cel::ParsedJsonListValue const&)
Unexecuted instantiation: cel::internal::PointerTraitsToAddress<cel::ParsedJsonMapValue, void>::Dispatch(cel::ParsedJsonMapValue const&)
Unexecuted instantiation: cel::internal::PointerTraitsToAddress<cel::Unique<google::protobuf::Message>, void>::Dispatch(cel::Unique<google::protobuf::Message> const&)
58
};
59
60
template <typename T>
61
0
constexpr auto to_address(const T& ptr ABSL_ATTRIBUTE_LIFETIME_BOUND) noexcept {
62
0
  return PointerTraitsToAddress<T>::Dispatch(ptr);
63
0
}
Unexecuted instantiation: auto cel::internal::to_address<cel::ParsedMessageValue>(cel::ParsedMessageValue const&)
Unexecuted instantiation: auto cel::internal::to_address<cel::ParsedJsonListValue>(cel::ParsedJsonListValue const&)
Unexecuted instantiation: auto cel::internal::to_address<cel::ParsedJsonMapValue>(cel::ParsedJsonMapValue const&)
Unexecuted instantiation: auto cel::internal::to_address<cel::Unique<google::protobuf::Message> >(cel::Unique<google::protobuf::Message> const&)
64
#endif
65
66
}  // namespace cel::internal
67
68
#endif  // THIRD_PARTY_CEL_CPP_INTERNAL_TO_ADDRESS_H_