TotalOrdering and Id implementations, related to T28
This commit is contained in:
parent
12628f3689
commit
e7953fc7e0
1
examples/.gitignore
vendored
Normal file
1
examples/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.out
|
41
examples/id.cpp
Normal file
41
examples/id.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "mvcc/id.hpp"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
int main() {
|
||||
|
||||
Id id0(0);
|
||||
Id id1(1);
|
||||
Id id2(1);
|
||||
Id id3(id2);
|
||||
Id id4 = id3;
|
||||
Id id5(5);
|
||||
|
||||
cout << id5 << " " << id0 << endl;
|
||||
|
||||
if (id0 < id5)
|
||||
cout << "id0 < id5" << endl;
|
||||
|
||||
if (id1 == id2)
|
||||
cout << "are equal" << endl;
|
||||
|
||||
if (id3 == id4)
|
||||
cout << "id3 == id4" << endl;
|
||||
|
||||
if (id5 > id0)
|
||||
cout << "id5 > id0" << endl;
|
||||
|
||||
if (id5 != id3)
|
||||
cout << "id5 != id3" << endl;
|
||||
|
||||
if (id1 >= id2)
|
||||
cout << "id1 >= id2" << endl;
|
||||
|
||||
if (id3 <= id4)
|
||||
cout << "id3 <= id4" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
29
mvcc/id.hpp
Normal file
29
mvcc/id.hpp
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <ostream>
|
||||
#include <stdint.h>
|
||||
#include "utils/total_ordering.hpp"
|
||||
|
||||
class Id : public TotalOrdering<Id>
|
||||
{
|
||||
public:
|
||||
Id(uint64_t id) : id(id) {}
|
||||
|
||||
friend bool operator<(const Id& a, const Id& b)
|
||||
{
|
||||
return a.id < b.id;
|
||||
}
|
||||
|
||||
friend bool operator==(const Id& a, const Id& b)
|
||||
{
|
||||
return a.id == b.id;
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& stream, const Id& id)
|
||||
{
|
||||
return stream << id.id;
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t id;
|
||||
};
|
@ -8,9 +8,18 @@ struct TotalOrdering
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
friend bool operator>(const Derived& a, const Derived& b)
|
||||
friend bool operator<=(const Derived& a, const Derived& b)
|
||||
{
|
||||
return !(a == b);
|
||||
return a < b || a == b;
|
||||
}
|
||||
|
||||
friend bool operator>(const Derived& a, const Derived& b)
|
||||
{
|
||||
return !(a <= b);
|
||||
}
|
||||
|
||||
friend bool operator>=(const Derived& a, const Derived& b)
|
||||
{
|
||||
return !(a < b);
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user