/** * @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 #include #include namespace mix_cc { /** * @brief 普通的元素查询,如果元素在容器中,返回true,否则返回false * @tparam Container * @tparam T * @param container 容器 * @param element 元素 * @return std::enable_if_t::value, bool> */ template std::enable_if_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 迭代器查询,如果迭代器在容器中,返回true,否则返回false * @tparam Container * @tparam I * @param container 容器 * @param iter 迭代器 * @return std::enable_if_t::value, bool> */ template std::enable_if_t::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