xtd 1.0.0
Loading...
Searching...
No Matches
xtd::collections::concurrent::concurrent_stack< type_t > Class Template Reference
Inheritance diagram for xtd::collections::concurrent::concurrent_stack< type_t >:
xtd::object xtd::collections::concurrent::iproducer_consumer_collection< type_t > xtd::collections::generic::icollection< type_t > xtd::collections::generic::ienumerable< type_t > xtd::collections::generic::extensions::collection_common< type_t, icollection< type_t > > xtd::interface xtd::collections::generic::ienumerable_abstract xtd::collections::generic::extensions::enumerable_iterators< type_t, xtd::collections::generic::ienumerable< type_t > > xtd::collections::generic::extensions::enumerable< type_t, xtd::collections::generic::ienumerable< type_t > >

Definition

template<typename type_t>
class xtd::collections::concurrent::concurrent_stack< type_t >

Represents a thread-safe last in-first out (LIFO) collection.

Definition
template<typename type_t>
concurrent_stack()=default
Initializes a new instance of the xtd::collections::concurrent::concurrent_stack <type_t> class.
Defines methods to manipulate thread-safe collections intended for producer/consumer usage....
Definition iproducer_consumer_collection.hpp:30
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:40
Header
#include <xtd/collections/concurrent/iproducer_consumer_collection>
Namespace
xtd::collections::concurrent
Library
xtd.core

Public Aliases

using value_type
 Represents the concurrent bag value type.
using reference
 Represents the reference of list value type.
using const_reference
 Represents the const reference of list value type.
using collection_type
 Represents the concurrent bag collection type.

Public Conctructors

 concurrent_stack ()=default
 Initializes a new instance of the xtd::collections::concurrent::concurrent_stack <type_t> class.
 concurrent_stack (std::initializer_list< type_t > items)
 Constructs the container with the contents of the specified initializer list, and allocator.
 concurrent_stack (const xtd::collections::generic::ienumerable< value_type > &collection)
 Initializes a new instance of the xtd::collections::concurrent::concurrent_stack <type_t> class that contains elements copied from the specified collection.
template<xtd::iterable iterable_t>
 concurrent_stack (iterable_t &&items)
 Initializes a new instance of the xtd::iterable that contains elements copied from the specified collection and has sufficient capacity to accommodate the number of elements copied.

Public Properties

auto count () const noexcept -> xtd::usize override
 Gets the number of elements contained in the xtd::collections::generic::icollection.
auto is_empty () const noexcept -> bool
 Gets a value that indicates whether the xtd::collections::concurrent::concurrent_stack <type_t> is empty.
auto is_read_only () const noexcept -> bool override
 Gets a value indicating whether the xtd::collections::concurrent::concurrent_stack <type_t> is read-only.
auto is_synchronized () const noexcept -> bool override
 Gets a value indicating whether access to the xtd::collections::concurrent::concurrent_stack <type_t> is synchronized (thread safe).

Public Methods

auto clear () -> void override
 Removes all items from the xtd::collections::generic::icollection <type_t>.
auto copy_to (xtd::array< value_type > &array, xtd::usize array_index) const -> void override
 Copies the elements of the xtd::collections::concurrent::concurrent_stack <type_t> to an xtd::array, starting at a particular xtd::array index.
virtual auto push (const_reference item) -> void
 Adds an item to the end of the xtd::collections::concurrent::concurrent_stack <type_t>.
template<xtd::iterable iterable_t>
auto push_range (const iterable_t &items) -> void
 Inserts multiple objects at the top of the xtd::collections::concurrent::concurrent_stack <type_t> atomically.
template<xtd::iterable iterable_t>
auto push_range (const iterable_t &items, xtd::usize start_index, xtd::usize count) -> void
 Inserts multiple objects at the top of the xtd::collections::concurrent::concurrent_stack <type_t> atomically.
auto get_enumerator () const -> xtd::collections::generic::enumerator< value_type > override
 Returns an enumerator that iterates through a collection.
auto to_array () const -> xtd::array< value_type > override
 Copies the elements contained in the xtd::collections::concurrent::concurrent_stack <type_t> to a new array.
auto to_string () const noexcept -> xtd::string override
 Returns a xtd::string that represents the current object.
virtual auto try_pop (reference result) -> bool
 Tries to remove and return the object at the beginning of the concurrent stack.
template<xtd::iterable iterable_t>
auto try_pop_range (iterable_t &items) -> xtd::usize
 Attempts to pop and return multiple objects from the top of the xtd::collections::concurrent::concurrent_stack <type_t> atomically.
template<xtd::iterable iterable_t>
auto try_pop_range (iterable_t &items, xtd::usize start_index, xtd::usize count) -> xtd::usize
 Attempts to pop and return multiple objects from the top of the xtd::collections::concurrent::concurrent_stack <type_t> atomically.
auto try_peek (reference result) const -> bool
 Tries to return an object from the beginning of the xtd::collections::concurrent::concurrent_stack <type_t> without removing it.

Additional Inherited Members

using value_type
 Represents the xtd::collections::generic::icollection value type.
using value_type
 Represents the xtd::collections::generic::ienumerable value type.
using iterator
 Represents the iterator of xtd::collections::generic::ienumerable value type.
using const_iterator
 Represents the const iterator of xtd::collections::generic::ienumerable value type.
using iterator
 Represents the iterator of enumerable value type.
using const_iterator
 Represents the const iterator of enumerable value type.
using enumerable_type
 Represents the ienumerable enumerable type.
using value_type
 Represents the ienumerable value type.
using ienumerable
 Represents the ienumerable value type.
using list
 Represents the list value type.
 object ()=default
 Create a new instance of the ultimate base class object.
virtual auto equals (const object &obj) const noexcept -> bool
 Determines whether the specified object is equal to the current object.
virtual auto get_hash_code () const noexcept -> xtd::usize
 Serves as a hash function for a particular type.
virtual auto get_type () const noexcept -> type_object
 Gets the type of the current instance.
template<typename object_t>
auto memberwise_clone () const -> xtd::unique_ptr_object< object_t >
 Creates a shallow copy of the current object.
virtual auto copy_to (xtd::array< type_t > &array, xtd::usize array_index) const -> void=0
 Copies the elements of the xtd::collections::generic::icollection <type_t> to an xtd::array, starting at a particular xtd::array index.
virtual auto try_add (const type_t &item) -> bool=0
 Attempts to add an object to the xtd::collections::concurrent::iproducer_consumer_collection <type_t>.
virtual auto try_take (type_t &item) -> bool=0
 Attempts to remove and return an object from the xtd::collections::concurrent::iproducer_consumer_collection <type_t>.
virtual auto add (const type_t &item) -> void=0
 Adds an item to the xtd::collections::generic::icollection <type_t>.
virtual auto contains (const type_t &item) const noexcept -> bool=0
 Determines whether the xtd::collections::generic::icollection <type_t> contains a specific value.
virtual auto remove (const type_t &item) -> bool=0
 Removes the first occurrence of a specific object from the xtd::collections::generic::icollection <type_t>.
virtual auto begin () const -> const_iterator
 Returns an iterator to the first element of the enumerable.
virtual auto cbegin () const -> const_iterator
 Returns an iterator to the first element of the enumerable.
virtual auto cend () const -> const_iterator
 Returns an iterator to the element following the last element of the enumerable.
virtual auto end () const -> const_iterator
 Returns an iterator to the element following the last element of the enumerable.
auto aggregate (func_t &&funcfunc) const -> type_t
 Applies an accumulator function over a sequence.
auto all (predicate_t &&predicatepredicate) const -> bool
 Determines whether all elements of a sequence satisfy a condition.
auto any () const noexcept -> bool
 Determines whether a sequence contains any elements.
auto append (element_t &&element) const noexcept -> xtd::collections::generic::enumerable_generator< type_t >
 Appends a value to the end of the sequence.
auto as_enumerable () const noexcept
 Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
auto average () const noexcept
 Computes the average of a sequence of value_t values.
auto cast () const noexcept -> xtd::collections::generic::enumerable_generator< result_t >
 Casts the elements of an xtd::collections::generic::ienumerable to the specified type.
auto chunk (xtd::usize size) const -> xtd::collections::generic::enumerable_generator< xtd::array< type_t > >
 Splits the elements of a sequence into chunks of size at most size.
auto concat (second_t &&second) const noexcept -> xtd::collections::generic::enumerable_generator< type_t >
 Concatenates two sequences.
auto contains (type_t &&value) const noexcept -> bool
 Determines whether a sequence contains a specified element by using the default equality comparer.
auto count () const noexcept -> xtd::usize
 Returns the number of elements in current sequence.
auto count_by (key_selector_t &&key_selector) const noexcept
 Returns the count of elements in the current sequence grouped by key.
auto default_if_empty () const noexcept -> xtd::collections::generic::enumerable_generator< type_t >
 Returns the elements of the specified sequence or the type parameter's default value in a singleton collection if the current sequence is empty.
auto distinct () const noexcept -> xtd::collections::generic::enumerable_generator< type_t >
 Returns distinct elements from a sequence by using the default equality comparer to compare values.
auto first () const -> type_t
 Returns the first element of a sequence.
auto first_or_default (predicate_t &&predicatepredicate, type_t &&default_value) const noexcept -> type_t
 Returns the first element of the sequence that satisfies a condition, or a specified default value if no such element is found.
auto last () const -> type_t
 Returns the last element of a sequence.
auto max () const -> type_t
 Returns the maximum value in a sequence of xtd::numeric values.
auto min () const -> type_t
 Returns the minimum value in a sequence of xtd::numeric values.
auto order () const -> xtd::collections::generic::enumerable_generator< type_t >
 Sorts the elements of a sequence in ascending order.
auto order_by (const std::function< type_t(const type_t &)> &key_selector) const
 Sorts the elements of a sequence in ascending order according to a key.
auto order_by_descending (const std::function< key_t(const type_t &)> &key_selector) const
 Sorts the elements of a sequence in descending order according to a key.
auto reverse () const -> xtd::collections::generic::enumerable_generator< type_t >
 Inverts the order of the elements in a sequence.
auto select (auto &&selector) const
 Projects each element of a sequence into a new form.
auto sequence_equal (second_t &&second) const -> bool
 Determines whether two sequences are equal by comparing the elements by using the default equality comparer for their type.
auto shuffle () const -> xtd::collections::generic::enumerable_generator< type_t >
 Shuffles the order of the elements of a sequence.
auto skip (xtd::usize count) const -> xtd::collections::generic::enumerable_generator< type_t >
 Bypasses a specified number of elements in a sequence and then returns the remaining elements.
auto skip_while (auto &&predicatepredicate) const -> xtd::collections::generic::enumerable_generator< type_t >
 Bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements.
auto take (xtd::usize count) const -> xtd::collections::generic::enumerable_generator< type_t >
 Returns a specified number of contiguous elements from the start of a sequence.
auto take_while (auto &&predicatepredicate) const -> xtd::collections::generic::enumerable_generator< type_t >
 Returns elements from a sequence as long as a specified condition is true, and then skips the remaining elements.
auto to_array () const -> xtd::array< type_t >
 Creates a xtd::array <type_t> from an xtd::collections::generic::ienumerable <type_t>.
auto to_list () const -> xtd::collections::generic::list< type_t >
 Creates a xtd::collections::generic::list <type_t> from an xtd::collections::generic::ienumerable <type_t>.
auto where (auto &&predicatepredicate) const
 Filters a sequence of values based on a predicate.
auto zip (second_t &&second) const -> xtd::collections::generic::enumerable_generator< std::tuple< type_t, xtd::iterable_value_type< second_t > > >
 Produces a sequence of tuples with elements from the two specified sequences.
virtual auto empty () const noexcept -> bool
 Checks whether the container is empty.
virtual auto size () const noexcept -> xtd::usize
 Gets the number of elements contained in the xtd::collections::generic::icollection <type_t>.
virtual auto operator<< (const type_t &item) -> icollection< type_t > &
 The shift left operator adds an item to the xtd::collections::generic::icollection <type_t>.
virtual auto operator>> (const type_t &item) -> icollection< type_t > &
 The shift right operator removes the first occurrence of a specific object from the xtd::collections::generic::icollection <type_t>.
template<typename object_a_t, typename object_b_t>
static auto equals (const object_a_t &object_a, const object_b_t &object_b) noexcept -> bool
 Determines whether the specified object instances are considered equal.
template<typename object_a_t, typename object_b_t>
static auto reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept -> bool
 Determines whether the specified object instances are the same instance.
static auto to_const_iterator (typename source_collection_t::const_iterator &value, const source_collection_t &source_collection, const target_collection_t &target_collection) noexcept -> typename target_collection_t::const_iterator
 Converts source iterator to target iterator.
static auto to_iterator (typename source_collection_t::const_iterator &value, const source_collection_t &source_collection, const target_collection_t &target_collection) noexcept -> typename target_collection_t::const_iterator
 Converts source iterator to target iterator.

Member Typedef Documentation

◆ value_type

template<typename type_t>
using xtd::collections::concurrent::concurrent_stack< type_t >::value_type

Represents the concurrent bag value type.

◆ reference

template<typename type_t>
using xtd::collections::concurrent::concurrent_stack< type_t >::reference

Represents the reference of list value type.

◆ const_reference

template<typename type_t>
using xtd::collections::concurrent::concurrent_stack< type_t >::const_reference

Represents the const reference of list value type.

◆ collection_type

template<typename type_t>
using xtd::collections::concurrent::concurrent_stack< type_t >::collection_type

Represents the concurrent bag collection type.

Constructor & Destructor Documentation

◆ concurrent_stack() [1/4]

template<typename type_t>
xtd::collections::concurrent::concurrent_stack< type_t >::concurrent_stack ( )
default

Initializes a new instance of the xtd::collections::concurrent::concurrent_stack <type_t> class.

◆ concurrent_stack() [2/4]

template<typename type_t>
xtd::collections::concurrent::concurrent_stack< type_t >::concurrent_stack ( std::initializer_list< type_t > items)
inline

Constructs the container with the contents of the specified initializer list, and allocator.

Parameters
itemsThe initializer list to initialize the elements of the container with.

◆ concurrent_stack() [3/4]

template<typename type_t>
xtd::collections::concurrent::concurrent_stack< type_t >::concurrent_stack ( const xtd::collections::generic::ienumerable< value_type > & collection)
inline

Initializes a new instance of the xtd::collections::concurrent::concurrent_stack <type_t> class that contains elements copied from the specified collection.

◆ concurrent_stack() [4/4]

template<typename type_t>
template<xtd::iterable iterable_t>
xtd::collections::concurrent::concurrent_stack< type_t >::concurrent_stack ( iterable_t && items)
inline

Initializes a new instance of the xtd::iterable that contains elements copied from the specified collection and has sufficient capacity to accommodate the number of elements copied.

Parameters
itemsThe iterable whose elements are copied to the new xtd::collections::concurrent::concurrent_stack <type_t>.

Member Function Documentation

◆ count()

template<typename type_t>
auto xtd::collections::concurrent::concurrent_stack< type_t >::count ( ) const -> xtd::usize
inlinenodiscardoverridevirtualnoexcept

Gets the number of elements contained in the xtd::collections::generic::icollection.

Returns
The number of elements contained in the xtd::collections::generic::icollection.

Implements xtd::collections::concurrent::iproducer_consumer_collection< type_t >.

◆ is_empty()

template<typename type_t>
auto xtd::collections::concurrent::concurrent_stack< type_t >::is_empty ( ) const -> bool
inlinenodiscardnoexcept

Gets a value that indicates whether the xtd::collections::concurrent::concurrent_stack <type_t> is empty.

Returns
true if the xtd::collections::concurrent::concurrent_stack <type_t> is empty; otherwise, false.
Remarks
or determining whether the collection contains any items, use of this property is recommended rather than retrieving the number of items from the xtd::collections::concurrent::concurrent_stack::count property and comparing it to 0. However, as this collection is intended to be accessed concurrently, it may be the case that another thread will modify the collection after xtd::collections::concurrent::concurrent_stack::is_empty returns, thus invalidating the result.

◆ is_read_only()

template<typename type_t>
auto xtd::collections::concurrent::concurrent_stack< type_t >::is_read_only ( ) const -> bool
inlinenodiscardoverridevirtualnoexcept

Gets a value indicating whether the xtd::collections::concurrent::concurrent_stack <type_t> is read-only.

Returns
true if the xtd::collections::concurrent::concurrent_stack <type_t> is read-only; otherwise, false.
Remarks
A collection that is read-only does not allow the addition or removal of elements after the collection is created. Note that read-only in this context does not indicate whether individual elements of the collection can be modified, since the xtd::collections::concurrent::concurrent_stack <type_t> interface only supports addition and removal operations. For example, the xtd::collections::concurrent::concurrent_stack::is_read_only property of an array that is cast or converted to an xtd::collections::concurrent::concurrent_stack <type_t> object returns true, even though individual array elements can be modified.

Implements xtd::collections::generic::icollection< type_t >.

◆ is_synchronized()

template<typename type_t>
auto xtd::collections::concurrent::concurrent_stack< type_t >::is_synchronized ( ) const -> bool
inlinenodiscardoverridevirtualnoexcept

Gets a value indicating whether access to the xtd::collections::concurrent::concurrent_stack <type_t> is synchronized (thread safe).

Returns
true if access to the ICollection is synchronized (thread safe); otherwise, false.
Remarks
xtd::collections::concurrent::iproducer_consumer_collection::sync_root returns an object, which can be used to synchronize access to the xtd::collections::generic::icollection.
Most collection classes in the xtd::collections namespace also implement a Synchronized method, which provides a synchronized wrapper around the underlying collection.
Enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.
The following code example shows how to lock the collection using the xtd::collections::concurrent::iproducer_consumer_collection::sync_root property during the entire enumeration.
icollection& my_collection = some_collection;
lock(my_collection.sync_root()) {
for (const auto& item : my_collection) {
// Insert your code here.
}
}
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...
generic::icollection< xtd::any_object > icollection
Defines size, enumerators, and synchronization methods for all nongeneric collections.
Definition icollection.hpp:32

Implements xtd::collections::concurrent::iproducer_consumer_collection< type_t >.

◆ clear()

template<typename type_t>
auto xtd::collections::concurrent::concurrent_stack< type_t >::clear ( ) -> void
inlineoverridevirtual

Removes all items from the xtd::collections::generic::icollection <type_t>.

Exceptions
xtd::not_supported_exceptionThe xtd::collections::generic::icollection <type_t> is read-only.
Remarks
xtd::collections::generic::icollection::count must be set to 0, and references to other objects from elements of the collection must be released.

Implements xtd::collections::generic::icollection< type_t >.

◆ copy_to()

template<typename type_t>
auto xtd::collections::concurrent::concurrent_stack< type_t >::copy_to ( xtd::array< value_type > & array,
xtd::usize array_index ) const -> void
inlineoverride

Copies the elements of the xtd::collections::concurrent::concurrent_stack <type_t> to an xtd::array, starting at a particular xtd::array index.

Parameters
arrayThe one-dimensional xtd::array that is the destination of the elements copied from xtd::collections::concurrent::concurrent_stack <type_t>. The xtd::array must have zero-based indexing.
array_indexThe zero-based index in array at which copying begins.
Exceptions
xtd::argument_exceptionThe number of elements in the source xtd::collections::concurrent::concurrent_stack <type_t> is greater than the available space from `array_index` to the end of the destination `array`.

◆ push()

template<typename type_t>
virtual auto xtd::collections::concurrent::concurrent_stack< type_t >::push ( const_reference item) -> void
inlinevirtual

Adds an item to the end of the xtd::collections::concurrent::concurrent_stack <type_t>.

Parameters
itemThe object to add to the xtd::collections::concurrent::concurrent_stack <type_t>.
Exceptions
xtd::not_supported_exceptionThe xtd::collections::concurrent::concurrent_stack <type_t> is read-only.

◆ push_range() [1/2]

template<typename type_t>
template<xtd::iterable iterable_t>
auto xtd::collections::concurrent::concurrent_stack< type_t >::push_range ( const iterable_t & items) -> void
inline

Inserts multiple objects at the top of the xtd::collections::concurrent::concurrent_stack <type_t> atomically.

Parameters
itemsThe objects to push onto the xtd::collections::concurrent::concurrent_stack <type_t>.
Remarks
When adding multiple items to the stack, using PushRange is a more efficient mechanism than using xtd::collections::concurrent::concurrent_stack::push one item at a time. Additionally, PushRange guarantees that all of the elements will be added atomically, meaning that no other threads will be able to inject elements between the elements being pushed. Items at lower indices in the items array will be pushed before items at higher indices.

◆ push_range() [2/2]

template<typename type_t>
template<xtd::iterable iterable_t>
auto xtd::collections::concurrent::concurrent_stack< type_t >::push_range ( const iterable_t & items,
xtd::usize start_index,
xtd::usize count ) -> void
inline

Inserts multiple objects at the top of the xtd::collections::concurrent::concurrent_stack <type_t> atomically.

Parameters
itemsThe objects to push onto the xtd::collections::concurrent::concurrent_stack <type_t>.
start_indexThe zero-based offset in items at which to begin inserting elements onto the top of the xtd::collections::concurrent::concurrent_stack <type_t>.
countThe number of elements to be inserted onto the top of the xtd::collections::concurrent::concurrent_stack <type_t>. @excpetion start_index plus count are greater than or equal to the length of items.
Remarks
When adding multiple items to the stack, using PushRange is a more efficient mechanism than using xtd::collections::concurrent::concurrent_stack::push one item at a time. Additionally, PushRange guarantees that all of the elements will be added atomically, meaning that no other threads will be able to inject elements between the elements being pushed. Items at lower indices in the items array will be pushed before items at higher indices.

◆ get_enumerator()

template<typename type_t>
auto xtd::collections::concurrent::concurrent_stack< type_t >::get_enumerator ( ) const -> xtd::collections::generic::enumerator< value_type >
inlinenodiscardoverridevirtual

Returns an enumerator that iterates through a collection.

Returns
An xtd::collections::generic::enumerator object that can be used to iterate through the collection.
Todo
: use enumerator with a snapshot of the collection instead reference : enumerator {items_, enumerator_mode::snapshot};

Implements xtd::collections::concurrent::iproducer_consumer_collection< type_t >.

◆ to_array()

template<typename type_t>
auto xtd::collections::concurrent::concurrent_stack< type_t >::to_array ( ) const -> xtd::array< value_type >
inlinenodiscardoverridevirtual

Copies the elements contained in the xtd::collections::concurrent::concurrent_stack <type_t> to a new array.

Returns
A new array containing the elements copied from the xtd::collections::concurrent::iproducer_consumer_collection <type_t.
Remarks
The method provides a snapshot of the underlying collection. It is possible for other threads to add or remove items immediately after the array is made.

Implements xtd::collections::concurrent::iproducer_consumer_collection< type_t >.

◆ to_string()

template<typename type_t>
auto xtd::collections::concurrent::concurrent_stack< type_t >::to_string ( ) const -> xtd::string
inlinenodiscardoverridevirtualnoexcept

Returns a xtd::string that represents the current object.

Returns
A string that represents the current object.

Reimplemented from xtd::object.

◆ try_pop()

template<typename type_t>
virtual auto xtd::collections::concurrent::concurrent_stack< type_t >::try_pop ( reference result) -> bool
inlinevirtual

Tries to remove and return the object at the beginning of the concurrent stack.

Parameters
itemWhen this method returns, if the operation was successful, result contains the object removed. If no object was available to be removed, the value is unspecified.
Returns
true if an element was removed and returned from the beginning of the xtd::collections::concurrent::concurrent_stack <type_t> successfully; otherwise, false.

◆ try_pop_range() [1/2]

template<typename type_t>
template<xtd::iterable iterable_t>
auto xtd::collections::concurrent::concurrent_stack< type_t >::try_pop_range ( iterable_t & items) -> xtd::usize
inline

Attempts to pop and return multiple objects from the top of the xtd::collections::concurrent::concurrent_stack <type_t> atomically.

Parameters
itemsThe xtd::iterable to which objects popped from the top of the ConcurrentStack<T> will be added.
Returns
The number of objects successfully popped from the top of the xtd::collections::concurrent::concurrent_stack <type_t> and inserted in items.
Remarks
When popping multiple items, if there is little contention on the stack, using xtd::collections::concurrent::concurrent_stack::try_pop_range can be more efficient than using xtd::collections::concurrent::concurrent_stack::try_pop once per item to be removed. Nodes fill the items array with the first item to be popped at the startIndex, the second item to be popped at startIndex + 1, and so on.

◆ try_pop_range() [2/2]

template<typename type_t>
template<xtd::iterable iterable_t>
auto xtd::collections::concurrent::concurrent_stack< type_t >::try_pop_range ( iterable_t & items,
xtd::usize start_index,
xtd::usize count ) -> xtd::usize
inline

Attempts to pop and return multiple objects from the top of the xtd::collections::concurrent::concurrent_stack <type_t> atomically.

Parameters
itemsThe xtd::iterable to which objects popped from the top of the ConcurrentStack<T> will be added.
start_indexThe zero-based offset in items at which to begin inserting elements from the top of the xtd::collections::concurrent::concurrent_stack <type_t>.
countThe number of elements to be popped from top of the xtd::collections::concurrent::concurrent_stack <type_t> and inserted into items. @excpetion start_index plus count are greater than or equal to the length of items.
Returns
The number of objects successfully popped from the top of the xtd::collections::concurrent::concurrent_stack <type_t> and inserted in items.
Remarks
When popping multiple items, if there is little contention on the stack, using xtd::collections::concurrent::concurrent_stack::try_pop_range can be more efficient than using xtd::collections::concurrent::concurrent_stack::try_pop once per item to be removed. Nodes fill the items array with the first item to be popped at the startIndex, the second item to be popped at startIndex + 1, and so on.

◆ try_peek()

template<typename type_t>
auto xtd::collections::concurrent::concurrent_stack< type_t >::try_peek ( reference result) const -> bool
inline

Tries to return an object from the beginning of the xtd::collections::concurrent::concurrent_stack <type_t> without removing it.

Parameters
resultWhen this method returns, result contains an object from the beginning of the xtd::collections::concurrent::concurrent_stack <type_t> or an unspecified value if the operation failed.
Returns
true if an object was returned successfully; otherwise, false.

The documentation for this class was generated from the following file: