#include <gtopt/work_pool.hpp>
template<typename T = void, typename Key = int64_t, typename KeyCompare = std::less<Key>>
Task class
Queued unit of work: a type-erased callable plus its scheduling requirements.
| Template parameters | |
|---|---|
| T | Result type of the stored callable (default void; the pool always queues void tasks). |
| Key | The priority-key type (must match the pool's key type). |
| KeyCompare | Comparator for the secondary sort. The default std::less<Key> gives "smaller key = higher priority". Use std::greater<Key> for "larger key = higher
priority" (the old pre-refactor behavior for int64_t). |
The callable is held in a std::move_only_function, so submit() moves its (move-only) std::packaged_task<R()> straight in — no shared_ptr indirection and no second shared state. The submitter keeps the matching std::future<R>; exceptions thrown by user code land in that future, so execute() does not throw for pool-submitted tasks.
Public types
- using key_compare = KeyCompare
- using key_type = Key
- using result_type = T
Constructors, destructors, conversion operators
Public functions
Function documentation
template<typename T, typename Key, typename KeyCompare>
bool gtopt:: Task<T, Key, KeyCompare>:: operator<(const Task& other) const noexcept
Returns true when this has lower priority than other (for use in a max-heap: the task at the top — the "greatest" — is dequeued first).
Ordering is driven by the priority_key ALONE — TaskPriority does NOT participate. Overloading the enum onto both queue ordering and the CPU-gate-bypass class created a trap: raising a task to High to let it bypass the CPU gate also reordered it ahead of every lower-tier task regardless of key (and demoting it back reintroduced the gate wedge). Gate-bypass now lives on the independent gate_bypass flag, leaving priority_key as the single source of truth for execution order.
Ordering:
Keycomparison viaKeyCompare:KeyCompare(key1, key2) == true⟹ key1 has higher priority. In a max-heap this meansoperator<returns true whenotherhas higher priority, i.e.KeyCompare(other.key, this.key). With the defaultstd::less<Key>: smaller key → higher priority.- Tie-break: older submission → higher priority.