1 Star 0 Fork 0

旷野芦苇殇/texteditor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
predicates.h 3.47 KB
一键复制 编辑 原始数据 按行查看 历史
旷野芦苇殇 提交于 2024-08-02 17:06 +08:00 . 初始化
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#pragma once
#include <functional>
#include <type_traits>
#include <utility>
namespace Utils
{
//////////////////
// find helpers
//////////////////
template<typename R, typename S, typename T>
decltype(auto) equal(R (S::*function)() const, T value)
{
// This should use std::equal_to<> instead of std::equal_to<T>,
// but that's not supported everywhere yet, since it is C++14
return std::bind<bool>(std::equal_to<T>(), value, std::bind(function, std::placeholders::_1));
}
template<typename R, typename S, typename T>
decltype(auto) equal(R S::*member, T value)
{
return std::bind<bool>(std::equal_to<T>(), value, std::bind(member, std::placeholders::_1));
}
//////////////////
// comparison predicates
//////////////////
template <typename Type>
auto equalTo(Type &&value)
{
return [value = std::forward<Type>(value)] (const auto &entry)
{
static_assert(std::is_same<std::decay_t<Type>,
std::decay_t<decltype(entry)>>::value,
"The container and predicate type of equalTo should be the same to prevent "
"unnecessary conversion.");
return entry == value;
};
}
template <typename Type>
auto unequalTo(Type &&value)
{
return [value = std::forward<Type>(value)] (const auto &entry)
{
static_assert(std::is_same<std::decay_t<Type>,
std::decay_t<decltype(entry)>>::value,
"The container and predicate type of unequalTo should be the same to prevent "
"unnecessary conversion.");
return !(entry == value);
};
}
template <typename Type>
auto lessThan(Type &&value)
{
return [value = std::forward<Type>(value)] (const auto &entry)
{
static_assert(std::is_same<std::decay_t<Type>,
std::decay_t<decltype(entry)>>::value,
"The container and predicate type of unequalTo should be the same to prevent "
"unnecessary conversion.");
return entry < value;
};
}
template <typename Type>
auto lessEqualThan(Type &&value)
{
return [value = std::forward<Type>(value)] (const auto &entry)
{
static_assert(std::is_same<std::decay_t<Type>,
std::decay_t<decltype(entry)>>::value,
"The container and predicate type of lessEqualThan should be the same to "
"prevent unnecessary conversion.");
return !(value < entry);
};
}
template <typename Type>
auto greaterThan(Type &&value)
{
return [value = std::forward<Type>(value)] (const auto &entry)
{
static_assert(std::is_same<std::decay_t<Type>,
std::decay_t<decltype(entry)>>::value,
"The container and predicate type of greaterThan should be the same to "
"prevent unnecessary conversion.");
return value < entry;
};
}
template <typename Type>
auto greaterEqualThan(Type &&value)
{
return [value = std::forward<Type>(value)] (const auto &entry)
{
static_assert(std::is_same<std::decay_t<Type>,
std::decay_t<decltype(entry)>>::value,
"The container and predicate type of greaterEqualThan should be the same to "
"prevent unnecessary conversion.");
return !(entry < value);
};
}
} // namespace Utils
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fengzhu2007/texteditor.git
git@gitee.com:fengzhu2007/texteditor.git
fengzhu2007
texteditor
texteditor
main

搜索帮助