OpenMS
3.7.0
Main Page
Related Pages
Topics
Namespaces
Concepts
Classes
Files
File List
File Members
Loading...
Searching...
No Matches
CheckedCast.h
Go to the documentation of this file.
1
// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2
// SPDX-License-Identifier: BSD-3-Clause
3
//
4
// --------------------------------------------------------------------------
5
// $Maintainer: Timo Sachsenberg $
6
// $Authors: Timo Sachsenberg $
7
// --------------------------------------------------------------------------
8
9
#pragma once
10
11
#include <
OpenMS/CONCEPT/Exception.h
>
12
#include <type_traits>
13
#include <utility>
14
15
namespace
OpenMS
16
{
18
template
<
typename
Target,
typename
Source>
19
Target
checkedCast
(Source value)
20
{
21
static_assert
(std::is_integral_v<Target> && std::is_integral_v<Source>);
22
if
(! std::in_range<Target>(value)) {
throw
Exception::OutOfRange
(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION); }
23
return
static_cast<
Target
>
(value);
24
}
25
}
// namespace OpenMS
Exception.h
OpenMS::Exception::OutOfRange
Out of range exception.
Definition
Exception.h:291
OpenMS
Main OpenMS namespace.
Definition
openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
OpenMS::checkedCast
Target checkedCast(Source value)
Convert an integer without silently wrapping or truncating an out-of-range value.
Definition
CheckedCast.h:19
OpenMS
CONCEPT
CheckedCast.h
Generated on Sat Nov 14 2026 01:19:53 for OpenMS by
1.9.8