-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: turuslan <turuslan.devbox@gmail.com>
- Loading branch information
Showing
45 changed files
with
712 additions
and
2,116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright Quadrivium LLC | ||
* All Rights Reserved | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <algorithm> | ||
#include <cstring> | ||
#include <span> | ||
|
||
#include "common/lexicographical_compare_three_way.hpp" | ||
|
||
// `std::span` doesn't have comparison operator functions. | ||
// Can't add function to neither `std::span` nor `namespace std`. | ||
// `SpanAdl{span}` wraps span and allows writing functions for `SpanAdl`. | ||
// `SpanAdl` overload will be selected by ADL. | ||
template <typename T> | ||
struct SpanAdl { | ||
std::span<T> v; | ||
}; | ||
template <typename T> | ||
SpanAdl(T &&t) -> SpanAdl<typename decltype(std::span{t})::element_type>; | ||
|
||
template <typename T> | ||
auto operator<=>(const SpanAdl<T> &l_, const auto &r_) | ||
requires(requires { std::span<const T>{r_}; }) | ||
{ | ||
auto &[l] = l_; | ||
std::span r{r_}; | ||
if constexpr (std::is_same_v<std::remove_cvref_t<T>, uint8_t>) { | ||
auto n = std::min(l.size(), r.size()); | ||
auto c = std::memcmp(l.data(), r.data(), n) <=> 0; | ||
return c != 0 ? c : l.size() <=> r.size(); | ||
} else { | ||
return cxx20::lexicographical_compare_three_way( | ||
l.begin(), l.end(), r.begin(), r.end()); | ||
} | ||
} | ||
|
||
template <typename T> | ||
bool operator==(const SpanAdl<T> &l_, const auto &r) | ||
requires(requires { std::span<const T>{r}; }) | ||
{ | ||
return (l_ <=> r) == 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.