-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pw_containers: Make item type deduction generic
This CL moves generic intrusive container and item functions to a standalone file, and renames them to avoid mentioning lists. This makes them available to be reused by other intrusive containers, such as the forthcoming intrusive maps. Affected functions include the item type deduction checks for and the assertions for containers and items before insertion or destruction. Change-Id: I5f6db3fe1a0fb5904349bbe021fa16cf62538721 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/235105 Lint: Lint 🤖 <[email protected]> Reviewed-by: Wyatt Hepler <[email protected]> Commit-Queue: Aaron Green <[email protected]> Reviewed-by: Taylor Cramer <[email protected]> Docs-Not-Needed: Aaron Green <[email protected]>
- Loading branch information
1 parent
25c8b84
commit 7f4759a
Showing
9 changed files
with
128 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2024 The Pigweed Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
// use this file except in compliance with the License. You may obtain a copy of | ||
// the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations under | ||
// the License. | ||
#pragma once | ||
|
||
#include <type_traits> | ||
|
||
namespace pw::containers::internal { | ||
|
||
/// Crashes with a diagnostic message that intrusive containers must be empty | ||
/// before destruction if the given `empty` parameter is not set. | ||
/// | ||
/// This function is standalone to avoid using PW_CHECK in a header file. | ||
void CheckIntrusiveContainerIsEmpty(bool empty); | ||
|
||
/// Crashes with a diagnostic message that items must not be in an intrusive | ||
/// container before insertion into an intrusive container or before destruction | ||
/// if the given `uncontained` parameter is not set. | ||
/// | ||
/// This function is standalone to avoid using PW_CHECK in a header file. | ||
void CheckIntrusiveItemIsUncontained(bool uncontained); | ||
|
||
// Gets the element type from an Item. This is used to check that an | ||
// IntrusiveList element class inherits from Item, either directly or through | ||
// another class. | ||
template <typename Item, typename T, bool kIsItem = std::is_base_of<Item, T>()> | ||
struct GetElementTypeFromItem { | ||
using Type = void; | ||
}; | ||
|
||
template <typename Item, typename T> | ||
struct GetElementTypeFromItem<Item, T, true> { | ||
using Type = typename T::ElementType; | ||
}; | ||
|
||
template <typename Item, typename T> | ||
using ElementTypeFromItem = typename GetElementTypeFromItem<Item, T>::Type; | ||
|
||
} // namespace pw::containers::internal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters