|
constexpr | function_queue () noexcept=default |
|
| function_queue (function_queue &&i_source) noexcept=default |
|
function_queue & | operator= (function_queue &&i_source) noexcept=default |
|
| ~function_queue () |
|
template<typename ELEMENT_COMPLETE_TYPE > |
void | push (ELEMENT_COMPLETE_TYPE &&i_source) |
|
template<typename ELEMENT_COMPLETE_TYPE , typename... CONSTRUCTION_PARAMS> |
void | emplace (CONSTRUCTION_PARAMS &&...i_construction_params) |
|
template<typename ELEMENT_TYPE > |
put_transaction< typename std::decay< ELEMENT_TYPE >::type > | start_push (ELEMENT_TYPE &&i_source) |
|
template<typename ELEMENT_TYPE , typename... CONSTRUCTION_PARAMS> |
put_transaction< ELEMENT_TYPE > | start_emplace (CONSTRUCTION_PARAMS &&...i_construction_params) |
|
template<typename ELEMENT_COMPLETE_TYPE > |
void | reentrant_push (ELEMENT_COMPLETE_TYPE &&i_source) |
|
template<typename ELEMENT_COMPLETE_TYPE , typename... CONSTRUCTION_PARAMS> |
void | reentrant_emplace (CONSTRUCTION_PARAMS &&...i_construction_params) |
|
template<typename ELEMENT_TYPE > |
reentrant_put_transaction< typename std::decay< ELEMENT_TYPE >::type > | start_reentrant_push (ELEMENT_TYPE &&i_source) |
|
template<typename ELEMENT_TYPE , typename... CONSTRUCTION_PARAMS> |
reentrant_put_transaction< ELEMENT_TYPE > | start_reentrant_emplace (CONSTRUCTION_PARAMS &&...i_construction_params) |
|
std::conditional< std::is_void< RET_VAL >::value, bool, optional< RET_VAL > >::type | try_consume (PARAMS...i_params) |
|
std::conditional< std::is_void< RET_VAL >::value, bool, optional< RET_VAL > >::type | try_consume (consume_operation &i_consume, PARAMS...i_params) |
|
std::conditional< std::is_void< RET_VAL >::value, bool, optional< RET_VAL > >::type | try_reentrant_consume (PARAMS...i_params) |
|
std::conditional< std::is_void< RET_VAL >::value, bool, optional< RET_VAL > >::type | try_reentrant_consume (reentrant_consume_operation &i_consume, PARAMS...i_params) |
|
template<function_type_erasure ERASURE_ = ERASURE, typename std::enable_if< ERASURE_!=function_manual_clear >::type * = nullptr> |
void | clear () noexcept |
|
bool | empty () noexcept |
|
template<typename CALLABLE, typename ALLOCATOR_TYPE = default_allocator, function_type_erasure ERASURE = function_standard_erasure>
class density::function_queue< CALLABLE, ALLOCATOR_TYPE, ERASURE >
Heterogeneous FIFO pseudo-container specialized to hold callable objects. function_queue is an adaptor for heter_queue.
- Template Parameters
-
function_queue<void(), default_allocator, ERASURE> queue;
queue.push([] { std::cout << "Hello"; });
queue.push([] { std::cout << " world"; });
queue.push([] { std::cout << "!!!"; });
queue.push([] { std::cout << std::endl; });
while (queue.try_consume())
;
If ERASURE == function_manual_clear, function_queue is not able to destroy the callable objects without invoking them. This produces a performance benefit, but:
Thread safeness: None. The user is responsible of avoiding data races.
Exception safeness: Any function of function_queue is noexcept or provides the strong exception guarantee.
std::conditional<std::is_void<RET_VAL>::value, bool, optional<RET_VAL> >::type try_consume |
( |
PARAMS... |
i_params | ) |
|
|
inline |
If the queue is not empty, invokes the first function object of the queue and then deletes it from the queue. Otherwise no operation is performed.
- Parameters
-
i_params... | parameters to be forwarded to the function object |
- Returns
- If RET_VAL is void, the return value is a boolean indicating whether a callable object was consumed. Otherwise the return value is an optional that contains the value returned by the callable object, or an empty optional in case the queue was empty.
This function is not reentrant: if the callable object accesses in any way this queue, the behavior is undefined. Use function_queue::try_reentrant_consume if you are not sure about what the callable object may do.
Throws: unspecified
Exception guarantee: strong (in case of exception the function has no observable effects).
function_queue<int(std::vector<std::string> & vect), default_allocator, ERASURE>
queue;
queue.push([](std::vector<std::string> & vect) {
vect.push_back("Hello");
return 2;
});
queue.push([](std::vector<std::string> & vect) {
vect.push_back(" world!");
return 3;
});
std::vector<std::string> strings;
int sum = 0;
while (auto const return_value = queue.try_consume(strings))
{
sum += *return_value;
}
assert(sum == 5);
for (auto const & str : strings)
std::cout << str;
std::cout << std::endl;
std::conditional<std::is_void<RET_VAL>::value, bool, optional<RET_VAL> >::type try_consume |
( |
consume_operation & |
i_consume, |
|
|
PARAMS... |
i_params |
|
) |
| |
|
inline |
If the queue is not empty, invokes the first function object of the queue and then deletes it from the queue. Otherwise no operation is performed.
The consume operation is performed using the provided consume_operation object. If the element to consume is in the same page of the last element visited by the provided consume operation, the implementation does not need to pin page. For this reason this overload of try_consume is much faster than the other.
- Parameters
-
i_consume | object to use for the consume operation |
i_params... | parameters to be forwarded to the function object |
- Returns
- If RET_VAL is void, the return value is a boolean indicating whether a callable object was consumed. Otherwise the return value is an optional that contains the value returned by the callable object, or an empty optional in case the queue was empty.
This function is not reentrant: if the callable object accesses in any way this queue, the behavior is undefined. Use function_queue::try_reentrant_consume if you are not sure about what the callable object may do.
Throws: unspecified
Exception guarantee: strong (in case of exception the function has no observable effects).
using Queue =
function_queue<int(std::vector<std::string> & vect), default_allocator, ERASURE>;
Queue queue;
queue.push([](std::vector<std::string> & vect) {
vect.push_back("Hello");
return 2;
});
queue.push([](std::vector<std::string> & vect) {
vect.push_back(" world!");
return 3;
});
std::vector<std::string> strings;
typename Queue::consume_operation consume;
int sum = 0;
while (auto const return_value = queue.try_consume(consume, strings))
{
sum += *return_value;
}
assert(sum == 5);
for (auto const & str : strings)
std::cout << str;
std::cout << std::endl;
std::conditional<std::is_void<RET_VAL>::value, bool, optional<RET_VAL> >::type try_reentrant_consume |
( |
PARAMS... |
i_params | ) |
|
|
inline |
If the queue is not empty, invokes the first function object of the queue and then deletes it from the queue. Otherwise no operation is performed.
- Parameters
-
i_params... | parameters to be forwarded to the function object |
- Returns
- If RET_VAL is void, the return value is a boolean indicating whether a callable object was consumed. Otherwise the return value is an optional that contains the value returned by the callable object, or an empty optional in case the queue was empty.
This function is reentrant: the callable object can access in any way this queue.
Throws: unspecified
Exception guarantee: strong (in case of exception the function has no observable effects).
function_queue<void(), default_allocator, ERASURE> queue;
auto func1 = [&queue] {
std::cout << (queue.empty() ? "The queue is empty" : "The queue is not empty")
<< std::endl;
};
auto func2 = [&queue, func1] { queue.push(func1); };
queue.push(func1);
queue.push(func2);
while (queue.try_reentrant_consume())
;
If the queue is not empty, invokes the first function object of the queue and then deletes it from the queue. Otherwise no operation is performed.
The consume operation is performed using the provided consume_operation object. If the element to consume is in the same page of the last element visited by the provided consume operation, the implementation does not need to pin page. For this reason this overload of try_reentrant_consume is much faster than the other.
- Parameters
-
i_consume | object to use for the consume operation |
i_params... | parameters to be forwarded to the function object |
- Returns
- If RET_VAL is void, the return value is a boolean indicating whether a callable object was consumed. Otherwise the return value is an optional that contains the value returned by the callable object, or an empty optional in case the queue was empty.
This function is reentrant: the callable object can access in any way this queue.
Throws: unspecified
Exception guarantee: strong (in case of exception the function has no observable effects).
function_queue<void(), default_allocator, ERASURE> queue;
auto func1 = [&queue] {
std::cout << (queue.empty() ? "The queue is empty" : "The queue is not empty")
<< std::endl;
};
auto func2 = [&queue, func1] { queue.push(func1); };
queue.push(func1);
queue.push(func2);
while (queue.try_reentrant_consume(consume))
;