algorithms
2.2.0
Framework-independent algorithms for the EIC
Toggle main menu visibility
Loading...
Searching...
No Matches
upcast.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <cstdint>
4
#include <string>
5
#include <type_traits>
6
7
// Safe type conversions (without narrowing) to be used for properties,
8
// gets arround the limitations of type-erasure without explicitly needing
9
// to specify template arguments in setProperty etc.
10
11
namespace
algorithms::detail
{
12
template
<
typename
T,
typename
Enable =
void
>
struct
upcast_type
{
using
type
= T; };
13
template
<
typename
UInt>
14
struct
upcast_type
<UInt, std::enable_if_t<std::is_integral_v<UInt> && !std::is_signed_v<UInt>>> {
15
using
type
= uint64_t;
16
};
17
template
<
typename
Int>
18
struct
upcast_type
<Int, std::enable_if_t<std::is_integral_v<Int> && std::is_signed_v<Int>>> {
19
using
type
= int64_t;
20
};
21
template
<
typename
Enum>
struct
upcast_type
<Enum, std::enable_if_t<std::is_enum_v<Enum>>> {
22
using
type
= int64_t;
23
};
24
template
<
typename
Float>
25
struct
upcast_type
<Float, std::enable_if_t<std::is_floating_point_v<Float>>> {
26
using
type
= double;
27
};
28
template
<
typename
String>
29
struct
upcast_type
<String, std::enable_if_t<std::is_convertible_v<String, std::string>>> {
30
using
type
= std::string;
31
};
32
template
<>
struct
upcast_type
<bool> {
using
type
= bool; };
33
34
// references and cv-qualifiers are removed first, so lvalues upcast as their value type
35
template
<
class
T>
using
upcast_type_t
=
typename
upcast_type<std::remove_cvref_t<T>
>::type;
36
37
template
<
class
T>
upcast_type_t<T>
upcast
(T&& value) {
return
value; }
38
39
}
// namespace algorithms::detail
40
algorithms::detail
Definition
algorithm.h:183
algorithms::detail::upcast
upcast_type_t< T > upcast(T &&value)
Definition
upcast.h:37
algorithms::detail::upcast_type_t
typename upcast_type< std::remove_cvref_t< T > >::type upcast_type_t
Definition
upcast.h:35
algorithms::detail::upcast_type< Enum, std::enable_if_t< std::is_enum_v< Enum > > >::type
int64_t type
Definition
upcast.h:22
algorithms::detail::upcast_type< Float, std::enable_if_t< std::is_floating_point_v< Float > > >::type
double type
Definition
upcast.h:26
algorithms::detail::upcast_type< Int, std::enable_if_t< std::is_integral_v< Int > &&std::is_signed_v< Int > > >::type
int64_t type
Definition
upcast.h:19
algorithms::detail::upcast_type< String, std::enable_if_t< std::is_convertible_v< String, std::string > > >::type
std::string type
Definition
upcast.h:30
algorithms::detail::upcast_type< UInt, std::enable_if_t< std::is_integral_v< UInt > &&!std::is_signed_v< UInt > > >::type
uint64_t type
Definition
upcast.h:15
algorithms::detail::upcast_type< bool >::type
bool type
Definition
upcast.h:32
algorithms::detail::upcast_type
Definition
upcast.h:12
algorithms::detail::upcast_type::type
T type
Definition
upcast.h:12
core
include
algorithms
detail
upcast.h
Generated by
1.17.0