46 template<
typename type_t,
typename container_t = std::deque<type_t>>
72 data_ = std::move(
stack.data_);
81 auto tmp = std::vector<type_t> {};
82 tmp.reserve(
stack.size());
84 while (!
stack.empty()) {
85 tmp.push_back(std::move(
stack.top()));
97 struct accessor :
public std::stack<type_t> {
static auto get() {
return &accessor::c;}};
98 const auto& underlying_items =
stack.*accessor::get();
99 data_->items =
base_type(underlying_items.begin(), underlying_items.end());
105 for (
const auto& item : collection)
106 data_->items.push(item);
116 stack(std::initializer_list<type_t> il) {
123 template < std::input_iterator input_iterator_t >
140 [[nodiscard]]
auto count() const noexcept ->
size_type override {
return data_->items.size();}
144 [[nodiscard]]
auto items()
const {
return std::stack<type_t>(std::deque<type_t>(data_->items.begin(), data_->items.end()));}
155 data_->items.clear();
163 for (
const auto& item : data_->items)
177 array_index +=
count() - 1;
178 for (
const auto& item : data_->items)
179 array[array_index--] = item;
194 data_->items.push(value);
202 data_->items.push(std::move(value));
212 return data_->items.capacity();
218 struct stack_enumerator :
public ienumerator < value_type > {
221 [[nodiscard]]
const value_type& current()
const override {
227 [[nodiscard]]
bool move_next()
override {
229 if (index_++ && iterator_ != items_.data_->items.crend()) ++iterator_;
230 else iterator_ = items_.data_->items.crbegin();
231 return iterator_ != items_.data_->items.crend();
234 void reset()
override {
236 version_ = items_.data_->version;
237 iterator_ = items_.data_->items.crend();
286 for (
auto&
i : data_->items)
288 data_->items = std::move(temp);
296 if (!
try_peek(result))
return false;
306 result =
count() ? data_->items.top() : type_t {};
322 data_->items = std::move(
other.data_->items);
330 data_->items =
items;
337 operator std::stack<type_t>()
const {
return items();}
341 auto is_read_only() const noexcept ->
bool override {
return false;}
344 auto add(
const type_t& value) ->
void override {
push(value);}
345 auto remove(
const type_t&) ->
bool override {
return false;}
359 template <
class type_t,
typename container_t>
362 template <
class type_t,
typename container_t>
365 template <
class type_t>
368 template <
class type_t>
371 template<
typename input_iterator_t>
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
virtual auto length() const noexcept -> size_type
Gets a size that represents the total number of elements in all the dimensions of the array.
Definition basic_array.hpp:122
static auto join(const basic_string &separator, const collection_t &values) noexcept -> basic_string
Definition basic_string.hpp:1258
Provides a raw, contiguous memory based LIFO (last-in, first-out) stack.
Definition raw_stack.hpp:43
typename container_type::const_reverse_iterator const_reverse_iterator
Const reverse iterator type.
Definition raw_stack.hpp:55
Defines methods to manipulate generic collections.
Definition icollection.hpp:45
virtual auto sync_root() const noexcept -> const xtd::object &=0
Gets an object that can be used to synchronize access to the the xtd::collections::generic::icollecti...
virtual auto is_synchronized() const noexcept -> bool=0
Gets a value indicating whether access to the xtd::collections::generic::icollection <type_t> is sync...
virtual auto count() const noexcept -> xtd::usize=0
Gets the number of elements contained in the xtd::collections::generic::icollection <type_t>.
typename xtd::collections::generic::ienumerable< xtd::any_object >::value_type value_type
Definition icollection.hpp:51
virtual auto is_read_only() const noexcept -> bool=0
Gets a value indicating whether the xtd::collections::generic::icollection <type_t> is read-only.
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:40
typename xtd::collections::generic::extensions::enumerable_iterators< xtd::any_object, xtd::collections::generic::ienumerable< xtd::any_object > >::iterator iterator
Definition ienumerable.hpp:48
Supports a simple iteration over a generic collection.
Definition ienumerator.hpp:58
Represents a variable size last-in-first-out (LIFO) collection of instances of the same specified typ...
Definition stack.hpp:47
auto push(const_reference value) -> void
Adds an object to the end of the xtd::collections::generic::stack <type_t>.
Definition stack.hpp:193
const value_type & const_reference
Represents the const reference of list value type.
Definition stack.hpp:61
stack()=default
Initializes a new instance of the xtd::collections::generic::stack <type_t> class that is empty and h...
stack(const ienumerable< value_type > &collection)
Initializes a new instance of the xtd::collections::generic::stack <type_t> class that contains eleme...
Definition stack.hpp:104
auto ensure_capacity(size_type capacity) -> size_type
Ensures that the capacity of this stack is at least the specified capacity. If the current capacity i...
Definition stack.hpp:210
stack(std::stack< type_t > &&stack)
Move constructor with specified stack.
Definition stack.hpp:80
auto try_peek(value_type &result) const noexcept -> bool
Returns a value that indicates whether there is an object at the beginning of the xtd::collections::g...
Definition stack.hpp:305
stack(const std::stack< type_t > &stack)
Default copy constructor with specified stack.
Definition stack.hpp:96
auto capacity() const noexcept -> size_type
Definition stack.hpp:136
auto trim_excess(size_type capacity) -> void
Sets the capacity of a xtd::collections::generic::stack <type_t> object to the specified number of en...
Definition stack.hpp:282
auto try_pop(value_type &result) noexcept -> bool
Removes the object at the beginning of the xtd::collections::generic::stack <type_t>,...
Definition stack.hpp:295
auto operator=(const stack &other) -> stack &=default
Copy assignment operator. Replaces the contents with a copy of the contents of other.
xtd::collections::generic::helpers::raw_stack< value_type, container_t > base_type
Represents the list base type.
Definition stack.hpp:55
auto items() const
Gets a std::stack<type_t>.
Definition stack.hpp:144
auto count() const noexcept -> size_type override
Gets the number of nodes actually contained in the xtd::collections::generic::stack <type_t>.
Definition stack.hpp:140
auto to_string() const noexcept -> string override
Returns a xtd::string that represents the current object.
Definition stack.hpp:269
stack(stack &&stack)
Move constructor with specified stack.
Definition stack.hpp:71
stack(input_iterator_t first, input_iterator_t last)
Constructs the container with the contents of the range [first, last).
Definition stack.hpp:124
auto peek() const -> value_type
Returns the object at the beginning of the xtd::collections::generic::stack <type_t> without removing...
Definition stack.hpp:253
auto trim_excess() -> void
Sets the capacity to the actual number of elements in the xtd::collections::generic::stack <type_t>,...
Definition stack.hpp:275
xtd::usize size_type
Represents the list size type (usually xtd::usize).
Definition stack.hpp:57
stack(const stack &stack)=default
Default copy constructor with specified stack.
typename icollection< type_t >::value_type value_type
Represents the list value type.
Definition stack.hpp:53
auto to_array() const -> xtd::array< value_type >
Copies the xtd::collections::generic::stack <type_t> elements to a new array.
Definition stack.hpp:261
auto copy_to(xtd::array< type_t > &array, size_type array_index) const -> void override
Copies the entire xtd::colllections::generic::linked_list <type_t> to a compatible one-dimensional ar...
Definition stack.hpp:175
auto contains(const_reference value) const noexcept -> bool override
Determines whether an element is in the xtd::collections::generic::stack <type_t>.
Definition stack.hpp:162
auto pop() -> value_type
Removes and returns the object at the beginning of the xtd::collections::generic::stack <type_t>.
Definition stack.hpp:185
enumerator< value_type > get_enumerator() const noexcept override
Returns an enumerator that iterates through the xtd::collections::generic::stack <type_t>.
Definition stack.hpp:217
stack(std::initializer_list< type_t > il)
Constructs the container with the contents of the specified initializer list, and allocator.
Definition stack.hpp:116
stack(size_type capacity)
Initializes a new instance of the xtd::collections::generic::stack <type_t> class that is empty and h...
Definition stack.hpp:111
auto clear() -> void override
Removes all elements from the xtd::collections::generic::stack <type_t>.
Definition stack.hpp:154
auto push(value_type &&value) -> void
Adds an object to the end of the xtd::collections::generic::stack <type_t>.
Definition stack.hpp:201
value_type & reference
Represents the reference of list value type.
Definition stack.hpp:59
static auto throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current()) -> void
Throws an exption with specified exception case.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:45
object()=default
Create a new instance of the ultimate base class object.
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.hpp:115
Contains xtd::collections::generic::icollection <type_t> interface.
generic::stack< xtd::any_object > stack
Represents a collection of xtd::any_object.
Definition stack.hpp:31
@ argument_out_of_range
The argument is out of range.
Definition exception_case.hpp:35
@ invalid_operation
The operation is not valid.
Definition exception_case.hpp:65
#define self_
The self_ expression is a reference value expression whose value is the reference of the implicit obj...
Definition self.hpp:20
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
std::size_t usize
Represents an unsigned size of any object in bytes.
Definition usize.hpp:22
auto new_ptr(args_t &&... args) -> xtd::ptr< type_t >
The xtd::new_ptr operator creates a xtd::ptr object.
Definition new_ptr.hpp:24
@ other
The operating system is other.
Definition platform_id.hpp:60
@ i
The I key.
Definition console_key.hpp:104
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:16
The xtd::collections namespace contains interfaces and classes that define various collections of obj...
Definition any_pair.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
auto first() const -> read_only_span< type_t, count >
Obtains a subspan consisting of the first count elements of the sequence.
Definition read_only_span.hpp:249
auto last() const -> read_only_span< type_t, count >
Obtains a subspan consisting of the last N elements of the sequence.
Definition read_only_span.hpp:274
Contains xtd::collections::generic::helpers::raw_stack class.
Contains xtd::string alias.
Supports a simple iteration over a generic collection.
Definition enumerator.hpp:39
Implements a function object for performing comparisons. Unless specialised, invokes operator== on ty...
Definition equator.hpp:39
Contains xtd::usize type.