27 lines
636 B
C++
27 lines
636 B
C++
#pragma once
|
|
#include "mix_cc/fp/fplus_define.h"
|
|
#include <type_traits>
|
|
namespace mix_cc {
|
|
namespace fp {
|
|
/**
|
|
* @brief find element in container by maybe
|
|
* @tparam Container
|
|
* @tparam T
|
|
* @param container
|
|
* @param element
|
|
* @return maybe<typename Container::iterator>
|
|
*/
|
|
template <typename Container, typename T>
|
|
auto find(const Container& container, const T& element)
|
|
-> maybe<typename Container::const_iterator> {
|
|
// equals end, means there is NO element in container
|
|
auto iter = container.find(element);
|
|
if (iter == container.end()) {
|
|
return {};
|
|
}
|
|
return iter;
|
|
}
|
|
} // namespace fp
|
|
|
|
} // namespace mix_cc
|