WarpX
Loading...
Searching...
No Matches
IsIn.H
Go to the documentation of this file.
1/* Copyright 2022 Andrew Myers, Luca Fedeli, Maxence Thevenet
2 * Revathi Jambunathan
3 *
4 * This file is part of WarpX.
5 *
6 * License: BSD-3-Clause-LBNL
7 */
8
9#ifndef WARPX_UTILS_ALGORITHMS_ISIN_H_
10#define WARPX_UTILS_ALGORITHMS_ISIN_H_
11
12#include <algorithm>
13#include <vector>
14
16{
28 template <typename TV, typename TE,
29 class = typename std::enable_if_t<std::is_convertible_v<TE,TV>>>
30 bool is_in(const std::vector<TV>& vect,
31 const TE& elem)
32 {
33 return (std::find(vect.begin(), vect.end(), elem) != vect.end());
34 }
35
36
48 template <typename TV, typename TE,
49 class = typename std::enable_if_t<std::is_convertible_v<TE,TV>>>
50 bool any_of_is_in(const std::vector<TV>& vect,
51 const std::vector<TE>& elems)
52 {
53 return std::any_of(elems.begin(), elems.end(),
54 [&](const auto elem){return is_in(vect, elem);});
55 }
56}
57
58#endif //WARPX_UTILS_ALGORITHMS_ISIN_H_
Definition IsIn.H:16
bool is_in(const std::vector< TV > &vect, const TE &elem)
Returns true if an item of type TE is in a vector of TV objects (provided that TE can be converted in...
Definition IsIn.H:30
bool any_of_is_in(const std::vector< TV > &vect, const std::vector< TE > &elems)
Returns true if any of the items of a vector<TE> is contained in another vector<TV> (provided that TE...
Definition IsIn.H:50