Merge branch 'release-3.29'
[kiteware-cmake.git] / Source / cmConstStack.h
blobf0bca322481f6c118b09cd55f83f9be1ee052504
1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #pragma once
5 #include "cmConfigure.h" // IWYU pragma: keep
7 #include <memory>
9 /** Base class template for CRTP to represent a stack of constant values.
10 Provide value semantics, but use efficient reference-counting underneath
11 to avoid copies. */
12 template <typename T, typename Stack>
13 class cmConstStack
15 struct Entry;
16 std::shared_ptr<Entry const> TopEntry;
18 public:
19 /** Default-construct an empty stack. */
20 cmConstStack();
22 /** Get a stack with the given call context added to the top. */
23 Stack Push(T value) const;
25 /** Get a stack with the top level removed.
26 May not be called until after a matching Push. */
27 Stack Pop() const;
29 /** Get the value at the top of the stack.
30 This may be called only if Empty() would return false. */
31 T const& Top() const;
33 /** Return true if this stack is empty. */
34 bool Empty() const;
36 protected:
37 cmConstStack(std::shared_ptr<Entry const> parent, T value);
38 cmConstStack(std::shared_ptr<Entry const> top);