/proc/self/cwd/internal/noop_delete.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_NOOP_DELETE_H_ |
16 | | #define THIRD_PARTY_CEL_CPP_INTERNAL_NOOP_DELETE_H_ |
17 | | |
18 | | #include <type_traits> |
19 | | |
20 | | #include "absl/base/nullability.h" |
21 | | |
22 | | namespace cel::internal { |
23 | | |
24 | | // Like `std::default_delete`, except it does nothing. |
25 | | template <typename T> |
26 | | struct NoopDelete { |
27 | | static_assert(!std::is_function<T>::value, |
28 | | "NoopDelete cannot be instantiated for function types"); |
29 | | |
30 | | constexpr NoopDelete() noexcept = default; |
31 | | constexpr NoopDelete(const NoopDelete<T>&) noexcept = default; |
32 | | |
33 | | template < |
34 | | typename U, |
35 | | typename = std::enable_if_t<std::conjunction_v< |
36 | | std::negation<std::is_same<T, U>>, std::is_convertible<U*, T*>>>> |
37 | | // NOLINTNEXTLINE(google-explicit-constructor) |
38 | | constexpr NoopDelete(const NoopDelete<U>&) noexcept {} |
39 | | |
40 | 29.0k | constexpr void operator()(T* absl_nullable) const noexcept { |
41 | 29.0k | static_assert(sizeof(T) >= 0, "cannot delete an incomplete type"); |
42 | 29.0k | static_assert(!std::is_void<T>::value, "cannot delete an incomplete type"); |
43 | 29.0k | } cel::internal::NoopDelete<google::protobuf::MessageFactory>::operator()(google::protobuf::MessageFactory*) const Line | Count | Source | 40 | 14.5k | constexpr void operator()(T* absl_nullable) const noexcept { | 41 | 14.5k | static_assert(sizeof(T) >= 0, "cannot delete an incomplete type"); | 42 | 14.5k | static_assert(!std::is_void<T>::value, "cannot delete an incomplete type"); | 43 | 14.5k | } |
cel::internal::NoopDelete<google::protobuf::DescriptorPool const>::operator()(google::protobuf::DescriptorPool const*) const Line | Count | Source | 40 | 14.5k | constexpr void operator()(T* absl_nullable) const noexcept { | 41 | 14.5k | static_assert(sizeof(T) >= 0, "cannot delete an incomplete type"); | 42 | 14.5k | static_assert(!std::is_void<T>::value, "cannot delete an incomplete type"); | 43 | 14.5k | } |
Unexecuted instantiation: cel::internal::NoopDelete<google::protobuf::Arena>::operator()(google::protobuf::Arena*) const |
44 | | }; |
45 | | |
46 | | template <typename T> |
47 | 29.0k | inline constexpr NoopDelete<T> NoopDeleteFor() noexcept { |
48 | 29.0k | return NoopDelete<T>{}; |
49 | 29.0k | } cel::internal::NoopDelete<google::protobuf::MessageFactory> cel::internal::NoopDeleteFor<google::protobuf::MessageFactory>() Line | Count | Source | 47 | 14.5k | inline constexpr NoopDelete<T> NoopDeleteFor() noexcept { | 48 | 14.5k | return NoopDelete<T>{}; | 49 | 14.5k | } |
cel::internal::NoopDelete<google::protobuf::DescriptorPool const> cel::internal::NoopDeleteFor<google::protobuf::DescriptorPool const>() Line | Count | Source | 47 | 14.5k | inline constexpr NoopDelete<T> NoopDeleteFor() noexcept { | 48 | 14.5k | return NoopDelete<T>{}; | 49 | 14.5k | } |
Unexecuted instantiation: cel::internal::NoopDelete<google::protobuf::Arena> cel::internal::NoopDeleteFor<google::protobuf::Arena>() |
50 | | |
51 | | } // namespace cel::internal |
52 | | |
53 | | #endif // THIRD_PARTY_CEL_CPP_INTERNAL_NOOP_DELETE_H_ |