xo-alloc2: DX1CollectorIterator infra [WIP]
This commit is contained in:
parent
59c0311ed7
commit
bf27314688
30 changed files with 1041 additions and 176 deletions
59
include/xo/alloc2/cmpresult.hpp
Normal file
59
include/xo/alloc2/cmpresult.hpp
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/** @file cmpresult.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
enum class comparison : int32_t {
|
||||
invalid = -1,
|
||||
comparable = 0,
|
||||
incomparable = 1,
|
||||
};
|
||||
|
||||
struct cmpresult {
|
||||
cmpresult() : err_{comparison::invalid}, cmp_{0} {}
|
||||
cmpresult(comparison err, std::int16_t cmp) : err_{err}, cmp_{cmp} {}
|
||||
|
||||
static cmpresult incomparable() { return cmpresult(comparison::incomparable, 0); }
|
||||
static cmpresult lesser() { return cmpresult(comparison::comparable, -1); }
|
||||
static cmpresult equal() { return cmpresult(comparison::comparable, 0); }
|
||||
static cmpresult greater() { return cmpresult(comparison::comparable, +1); }
|
||||
|
||||
template<typename T>
|
||||
static cmpresult from_cmp(T && x, T && y) {
|
||||
if (x < y)
|
||||
return cmpresult::lesser();
|
||||
else if (x == y)
|
||||
return cmpresult::equal();
|
||||
else
|
||||
return cmpresult::greater();
|
||||
}
|
||||
|
||||
|
||||
bool is_equal() const { return (err_ == comparison::comparable) && (cmp_ == 0); }
|
||||
|
||||
/* -1 -> invalid (sentinel)
|
||||
* 0 -> comparable
|
||||
* 1 -> incomparable (e.g. iterators from different arenas)
|
||||
*/
|
||||
comparison err_ = comparison::invalid;
|
||||
/* <0 -> lesser; 0 -> equal, >0 -> greater */
|
||||
std::int16_t cmp_ = 0;
|
||||
};
|
||||
|
||||
inline std::ostream & operator<<(std::ostream & os,
|
||||
const cmpresult & x)
|
||||
{
|
||||
os << "<cmpresult " << xtag("err", x.err_) << xtag("cmp", x.cmp_) << ">";
|
||||
}
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end cmpresult.hpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue