diff --git a/BaseLib/Algorithm.h b/BaseLib/Algorithm.h new file mode 100644 index 0000000000000000000000000000000000000000..d05e60e7a0395497c76c4046e3bc919dbd01440a --- /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