aboutsummaryrefslogtreecommitdiff
path: root/Source/Utils/Algorithms/IsIn.H
diff options
context:
space:
mode:
authorGravatar Luca Fedeli <luca.fedeli@cea.fr> 2022-10-10 20:36:14 +0200
committerGravatar GitHub <noreply@github.com> 2022-10-10 11:36:14 -0700
commite9cc65ffeb0684a97618b67c2164d95ea497226c (patch)
treeed65f7ac86cc4e8945021dc36a79c8bc246c150d /Source/Utils/Algorithms/IsIn.H
parent56e04c1b911f9399662c4ff9ecf6630d686cc220 (diff)
downloadWarpX-e9cc65ffeb0684a97618b67c2164d95ea497226c.tar.gz
WarpX-e9cc65ffeb0684a97618b67c2164d95ea497226c.tar.zst
WarpX-e9cc65ffeb0684a97618b67c2164d95ea497226c.zip
Partial refactoring of the utils directory (#3404)
* initial work to clean WarpX Utils * remove AMRCore from Ionization tables * progress * refactoring of a part of the utils directory * fix bug * fixed bug * fixed bug * remove debug line accidentally slipped into the code * remove debug line accidentally slipped into the code * remove debug line accidentally slipped into the code * cleaning * fixed bug
Diffstat (limited to 'Source/Utils/Algorithms/IsIn.H')
-rw-r--r--Source/Utils/Algorithms/IsIn.H58
1 files changed, 58 insertions, 0 deletions
diff --git a/Source/Utils/Algorithms/IsIn.H b/Source/Utils/Algorithms/IsIn.H
new file mode 100644
index 000000000..c9d2f477e
--- /dev/null
+++ b/Source/Utils/Algorithms/IsIn.H
@@ -0,0 +1,58 @@
+/* Copyright 2022 Andrew Myers, Luca Fedeli, Maxence Thevenet
+ * Revathi Jambunathan
+ *
+ * This file is part of WarpX.
+ *
+ * License: BSD-3-Clause-LBNL
+ */
+
+#ifndef WARPX_UTILS_ALGORITHMS_ISIN_H_
+#define WARPX_UTILS_ALGORITHMS_ISIN_H_
+
+#include <algorithm>
+#include <vector>
+
+namespace utils::algorithms
+{
+ /** \brief Returns true if an item of type TE is in a vector
+ * of TV objects (provided that TE can be converted into TV), false otherwise
+ *
+ * @tparam TV the typename of the vector elements
+ * @tparam TE the typename of the item
+ *
+ * @param vect a vector of TV objects
+ * @param elem an object of type TE
+ *
+ * @return true if elem is in vect, false otherwise
+ */
+ template <typename TV, typename TE,
+ class = typename std::enable_if<std::is_convertible<TE,TV>::value>::type>
+ bool is_in(const std::vector<TV>& vect,
+ const TE& elem)
+ {
+ return (std::find(vect.begin(), vect.end(), elem) != vect.end());
+ }
+
+
+ /** \brief Returns true if any of the items of a vector<TE> is contained
+ * in another vector<TV> (provided that TE can be converted into TV)
+ *
+ * @tparam TV the typename of the first vector elements
+ * @tparam TV the typename of the second vector elements
+ *
+ * @param vect a vector of TV objects
+ * @param elems a vector of TE objects
+ *
+ * @return true if any element of elems is in vect, false otherwise
+ */
+ template <typename TV, typename TE,
+ class = typename std::enable_if<std::is_convertible<TE,TV>::value>::type>
+ bool any_of_is_in(const std::vector<TV>& vect,
+ const std::vector<TE>& elems)
+ {
+ return std::any_of(elems.begin(), elems.end(),
+ [&](const auto elem){return is_in(vect, elem);});
+ }
+}
+
+#endif //WARPX_UTILS_ALGORITHMS_ISIN_H_