Fix Safe Tuple Check: Now RVO does not cause problems

This commit is contained in:
sha512sum 2024-03-02 00:48:15 +00:00
parent 9c3b4e6ec0
commit b99dca868c

View file

@ -92,20 +92,22 @@ namespace impl {
template <typename T>
struct Getter {
friend consteval bool Magic(Getter<T>);
friend consteval auto Magic(Getter<T>);
};
template <typename T>
template <typename T, auto Insert>
struct Inserter {
friend consteval bool Magic(Getter<T>) {return true;};
friend consteval auto Magic(Getter<T>) -> decltype(auto) {
return Insert;
};
};
template <typename T>
struct SafeTupleChecker {
consteval SafeTupleChecker(SafeTupleChecker&&) {
std::ignore = Inserter<SafeTupleChecker<T>>{};
std::ignore = Inserter<SafeTupleChecker<T>, false>{};
};
consteval SafeTupleChecker(const SafeTupleChecker&) = default;
consteval SafeTupleChecker() = default;
@ -123,7 +125,8 @@ struct IsSafeTuple {
};
template <typename T>
struct IsSafeTuple<T, bool(TrueF(Get<0>(MakeTuple<T>(0, kSafeTupleChecker<T>))) && !Magic(Getter<SafeTupleChecker<T>>{})) ? false : false> {
struct IsSafeTuple<T, bool(TrueF(Get<0>(std::move(Get<0>(Tuple{MakeTuple<T>(0, kSafeTupleChecker<T>)}))))
&& Magic(Getter<SafeTupleChecker<T>>{})) ? false : false> {
static constexpr bool value = false;
};