C++ Channel
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
msd::blocking_iterator< Channel > Class Template Reference

An iterator that block the current thread, waiting to fetch elements from the channel. More...

#include <blocking_iterator.hpp>

Public Types

using value_type = typename Channel::value_type
 The type of the elements stored in the channel.
 
using reference = const typename Channel::value_type &
 Constant reference to the type of the elements stored in the channel.
 
using iterator_category = std::input_iterator_tag
 Supporting single-pass reading of elements.
 
using difference_type = std::ptrdiff_t
 Signed integral type for iterator difference.
 
using pointer = const value_type *
 Pointer type to the value_type.
 

Public Member Functions

 blocking_iterator (Channel &chan)
 Constructs a blocking iterator from a channel reference.
 
blocking_iterator< Channeloperator++ () const noexcept
 Advances the iterator to the next element.
 
reference operator* ()
 Retrieves and returns the next element from the channel.
 
bool operator!= (blocking_iterator< Channel >) const
 Makes iteration continue until the channel is closed and empty.
 

Detailed Description

template<typename Channel>
class msd::blocking_iterator< Channel >

An iterator that block the current thread, waiting to fetch elements from the channel.

Used to implement channel range-based for loop.

Template Parameters
ChannelInstance of channel.

Constructor & Destructor Documentation

◆ blocking_iterator()

template<typename Channel >
msd::blocking_iterator< Channel >::blocking_iterator ( Channel chan)
inlineexplicit

Constructs a blocking iterator from a channel reference.

Parameters
chanReference to the channel this iterator will iterate over.

Member Function Documentation

◆ operator!=()

template<typename Channel >
bool msd::blocking_iterator< Channel >::operator!= ( blocking_iterator< Channel ) const
inline

Makes iteration continue until the channel is closed and empty.

Returns
true if the channel is not closed or not empty (continue iterating).
false if the channel is closed and empty (stop iterating).

◆ operator*()

template<typename Channel >
reference msd::blocking_iterator< Channel >::operator* ( )
inline

Retrieves and returns the next element from the channel.

Returns
A const reference to the current element.

◆ operator++()

template<typename Channel >
blocking_iterator< Channel > msd::blocking_iterator< Channel >::operator++ ( ) const
inlinenoexcept

Advances the iterator to the next element.

Returns
The iterator itself.

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