26 #ifndef JAU_BASIC_ALGOS_HPP_
27 #define JAU_BASIC_ALGOS_HPP_
30 #include <type_traits>
87 template<
class InputIt,
class T>
88 constexpr InputIt
find(InputIt first, InputIt last,
const T& value)
90 for (; first != last; ++first) {
91 if (*first == value) {
112 template<
class InputIt,
class UnaryPredicate>
113 constexpr InputIt
find_if(InputIt first, InputIt last, UnaryPredicate p)
115 for (; first != last; ++first) {
137 template<
class InputIt,
class UnaryPredicate>
138 constexpr InputIt
find_if_not(InputIt first, InputIt last, UnaryPredicate q)
140 for (; first != last; ++first) {
162 template<
class InputIt,
class UnaryFunction>
163 constexpr UnaryFunction
for_each(InputIt first, InputIt last, UnaryFunction f)
165 for (; first != last; ++first) {
214 template<
class InputIt,
class UnaryFunction>
217 typedef typename InputIt::value_type value_type;
219 for (; first != last; ++first) {
220 f( *
const_cast<value_type*
>( & (*first) ) );
238 template<
class Mutex,
class InputIt,
class UnaryFunction>
239 constexpr UnaryFunction
for_each_mtx(Mutex &mtx, InputIt first, InputIt last, UnaryFunction f)
241 const std::lock_guard<Mutex> lock(mtx);
243 for (; first != last; ++first) {
257 template<
class InputArray,
class UnaryFunction>
258 constexpr UnaryFunction
for_each_idx(InputArray &array, UnaryFunction f)
260 const size_t size = array.size();
261 for (
size_t i = 0; i < size; ++i) {
279 template<
class Mutex,
class InputArray,
class UnaryFunction>
282 const std::lock_guard<Mutex> lock(mtx);
284 const size_t size = array.size();
285 for (
size_t i = 0; i < size; ++i) {
295 const typename T::value_type *
find_const(T& data,
typename T::value_type
const & elem,
298 for (
typename T::const_iterator first = data.cbegin(); !first.is_end(); ++first) {
299 if (*first == elem) {
306 const typename T::value_type *
find_const(T& data,
typename T::value_type
const & elem,
309 typename T::const_iterator first = data.cbegin();
310 typename T::const_iterator last = data.cend();
311 for (; first != last; ++first) {
312 if (*first == elem) {
322 template<
class T,
class UnaryFunction>
326 for (
typename T::const_iterator first = data.cbegin(); !first.is_end(); ++first) {
331 template<
class T,
class UnaryFunction>
335 typename T::const_iterator first = data.cbegin();
336 typename T::const_iterator last = data.cend();
337 for (; first != last; ++first) {
349 template<
class T,
class UnaryFunction>
353 for (
typename T::const_iterator first = data.cbegin(); !first.is_end(); ++first) {
354 f( *
const_cast<typename T::value_type*
>( & (*first) ) );
361 template<
class T,
class UnaryFunction>
365 typename T::const_iterator first = data.cbegin();
366 typename T::const_iterator last = data.cend();
367 for (; first != last; ++first) {
368 f( *
const_cast<typename T::value_type*
>( & (*first) ) );