OpenMS
EnumHelpers.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Chris Bielow $
6 // $Authors: Chris Bielow $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 
12 namespace OpenMS
13 {
14  namespace Helpers
15  {
18  template <class ContainerType>
19  Size indexOf(const ContainerType& cont, const typename ContainerType::value_type& val)
20  {
21  auto it = std::find(cont.begin(), cont.end(), val);
22  if (it == cont.end())
23  {
24  throw Exception::ElementNotFound(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, val);
25  }
26  return std::distance(cont.begin(), it);
27  }
28 
29  }
30 }
31 
32 
Element could not be found exception.
Definition: Exception.h:650
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:101
Size indexOf(const ContainerType &cont, const typename ContainerType::value_type &val)
Definition: EnumHelpers.h:19
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22