From 64cd00e1d154e7eaee0be02091d12df28521d99e Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <github@naumov.de>
Date: Thu, 21 Jun 2018 00:21:01 +0200
Subject: [PATCH] [BL] Implement findElement algorithm.

---
 BaseLib/Algorithm.h | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 BaseLib/Algorithm.h

diff --git a/BaseLib/Algorithm.h b/BaseLib/Algorithm.h
new file mode 100644
index 00000000000..d05e60e7a03
--- /dev/null
+++ b/BaseLib/Algorithm.h
@@ -0,0 +1,32 @@
+/**
+ * \file
+ *
+ * \copyright
+ * Copyright (c) 2012-2018, OpenGeoSys Community (http://www.opengeosys.org)
+ *            Distributed under a Modified BSD License.
+ *              See accompanying file LICENSE.txt or
+ *              http://www.opengeosys.org/project/license
+ *
+ */
+
+#pragma once
+
+#include <algorithm>
+#include "Error.h"
+
+namespace BaseLib
+{
+template <typename InputIt, typename Predicate>
+typename std::iterator_traits<InputIt>::reference findElement(
+    InputIt begin, InputIt end, Predicate predicate,
+    std::string const& error = "")
+{
+    auto it = std::find_if(begin, end, predicate);
+    if (it == end)
+    {
+        OGS_FATAL("Element not found in the input range; %s", error.c_str());
+    }
+    return *it;
+}
+
+}  // end namespace BaseLib
-- 
GitLab