template<typename T = void, typename Key = int64_t, typename KeyCompare = std::less<Key>>
gtopt::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

Task() defaulted
Task(const Task&) deleted
template<typename F>
Task(F&& func, BasicTaskRequirements<Key> req = {}) explicit constexpr
Task(Task&&) defaulted
~Task() defaulted

Public functions

auto age() const -> auto noexcept
void execute()
auto operator<(const Task& other) const -> bool noexcept
auto operator=(const Task&) -> Task& deleted
auto operator=(Task&&) -> Task& defaulted
auto requirements() const -> const BasicTaskRequirements<Key>& noexcept

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:

  1. Key comparison via KeyCompare: KeyCompare(key1, key2) == true ⟹ key1 has higher priority. In a max-heap this means operator< returns true when other has higher priority, i.e. KeyCompare(other.key, this.key). With the default std::less<Key>: smaller key → higher priority.
  2. Tie-break: older submission → higher priority.