RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
Casts.h
Go to the documentation of this file.
1/*
2 RawSpeed - RAW file decoder.
3
4 Copyright (C) 2023 Roman Lebedev
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19*/
20
21#pragma once
22
23#include "rawspeedconfig.h"
24#include <type_traits>
25
26namespace rawspeed {
27
28template <typename Ttgt, typename Tsrc>
29 requires(((std::is_integral_v<Tsrc> || std::is_floating_point_v<Tsrc>) &&
30 (std::is_integral_v<Ttgt> || std::is_floating_point_v<Ttgt>)) &&
31 !std::is_same_v<Tsrc, Ttgt>)
32constexpr RAWSPEED_READNONE Ttgt implicit_cast(Tsrc value) {
33#pragma GCC diagnostic push
34#pragma GCC diagnostic ignored "-Wconversion"
35#pragma GCC diagnostic ignored "-Wdouble-promotion"
36 return value;
37#pragma GCC diagnostic pop
38}
39
40// Sometimes through templates in some template instantiations
41// the types do end up being the same. This is fine.
42template <typename Ttgt, typename Tsrc>
43 requires(((std::is_integral_v<Tsrc> || std::is_floating_point_v<Tsrc>) &&
44 (std::is_integral_v<Ttgt> || std::is_floating_point_v<Ttgt>)) &&
45 std::is_same_v<Tsrc, Ttgt>)
46constexpr RAWSPEED_READNONE Ttgt implicit_cast(Tsrc value) {
47 return value;
48}
49
50} // namespace rawspeed
constexpr RAWSPEED_READNONE Ttgt implicit_cast(Tsrc value)
Definition Casts.h:32