eis/mix_cc/algorithm/is_found.h

58 lines
1.6 KiB
C
Raw Permalink Normal View History

/**
* @file mix_cc/algorithm/is_found.h
* @brief /
* @author Cat (null.null.null@qq.com)
* @version 0.1
* @date 2021-05-07
*
* Copyright: Baosight Co. Ltd.
* DO NOT COPY/USE WITHOUT PERMISSION
*
*/
#pragma once
#include <utility>
#include <typeindex>
#include <algorithm>
namespace mix_cc {
/**
* @brief truefalse
* @tparam Container
* @tparam T
* @param container
* @param element
* @return std::enable_if_t<!std::is_same<typename Container::iterator, T>::value, bool>
*/
template <typename Container, typename T>
std::enable_if_t<!std::is_same<typename Container::iterator, T>::value, bool>
is_found(const Container &container, const T &element) {
bool ret = true;
// equals end, means there is NO element in container
if (container.find(element) == container.end()) {
ret = false; // we can't find
}
return ret;
}
/**
* @brief truefalse
* @tparam Container
* @tparam I
* @param container
* @param iter
* @return std::enable_if_t<std::is_same<typename Container::iterator, I>::value, bool>
*/
template <typename Container, typename I>
std::enable_if_t<std::is_same<typename Container::iterator, I>::value, bool>
is_found(const Container &container, const I &iter) {
bool ret = true;
// equals end, means there is NO element in container
if (iter == container.end()) {
ret = false; // we can't find
}
return ret;
}
} // namespace mix_cc