alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
Integral.hpp
Go to the documentation of this file.
1/* Copyright 2022 Benjamin Worpitz, Bernhard Manfred Gruber
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
7#include <type_traits>
8
9namespace alpaka::meta
10{
11 //! The trait is true if all values of TSubset are contained in TSuperset.
12 template<typename TSuperset, typename TSubset>
13 using IsIntegralSuperset = std::integral_constant<
14 bool,
15 std::is_integral_v<TSuperset> && std::is_integral_v<TSubset>
16 && (
17 // If the signdness is equal, the sizes have to be greater or equal to be a superset.
18 ((std::is_unsigned_v<TSuperset>
19 == std::is_unsigned_v<TSubset>) &&(sizeof(TSuperset) >= sizeof(TSubset)))
20 // If the signdness is non-equal, the superset has to have at least one bit more.
21 || ((std::is_unsigned_v<TSuperset> != std::is_unsigned_v<TSubset>) &&(
22 sizeof(TSuperset) > sizeof(TSubset))))>;
23
24 //! The type that has the higher max value.
25 template<typename T0, typename T1>
26 using HigherMax = std::conditional_t<
27 (sizeof(T0) > sizeof(T1)),
28 T0,
29 std::conditional_t<((sizeof(T0) == sizeof(T1)) && std::is_unsigned_v<T0> && std::is_signed_v<T1>), T0, T1>>;
30
31 //! The type that has the lower max value.
32 template<typename T0, typename T1>
33 using LowerMax = std::conditional_t<
34 (sizeof(T0) < sizeof(T1)),
35 T0,
36 std::conditional_t<((sizeof(T0) == sizeof(T1)) && std::is_signed_v<T0> && std::is_unsigned_v<T1>), T0, T1>>;
37
38 //! The type that has the higher min value. If both types have the same min value, the type with the wider
39 //! range is chosen.
40 template<typename T0, typename T1>
41 using HigherMin = std::conditional_t<
42 (std::is_unsigned_v<T0> == std::is_unsigned_v<T1>),
43 std::conditional_t<
44 std::is_unsigned_v<T0>,
45 std::conditional_t<(sizeof(T0) < sizeof(T1)), T1, T0>,
46 std::conditional_t<(sizeof(T0) < sizeof(T1)), T0, T1>>,
47 std::conditional_t<std::is_unsigned_v<T0>, T0, T1>>;
48
49 //! The type that has the lower min value. If both types have the same min value, the type with the wider range
50 //! is chosen.
51 template<typename T0, typename T1>
52 using LowerMin = std::conditional_t<
53 (std::is_unsigned_v<T0> == std::is_unsigned_v<T1>),
54 std::conditional_t<(sizeof(T0) > sizeof(T1)), T0, T1>,
55 std::conditional_t<std::is_signed_v<T0>, T0, T1>>;
56} // namespace alpaka::meta
std::conditional_t<(sizeof(T0)< sizeof(T1)), T0, std::conditional_t<((sizeof(T0)==sizeof(T1)) &&std::is_signed_v< T0 > &&std::is_unsigned_v< T1 >), T0, T1 > > LowerMax
The type that has the lower max value.
Definition Integral.hpp:36
std::integral_constant< bool, std::is_integral_v< TSuperset > &&std::is_integral_v< TSubset > &&(((std::is_unsigned_v< TSuperset >==std::is_unsigned_v< TSubset >) &&(sizeof(TSuperset) >=sizeof(TSubset)))||((std::is_unsigned_v< TSuperset > !=std::is_unsigned_v< TSubset >) &&(sizeof(TSuperset) > sizeof(TSubset))))> IsIntegralSuperset
The trait is true if all values of TSubset are contained in TSuperset.
Definition Integral.hpp:22
std::conditional_t<(sizeof(T0) > sizeof(T1)), T0, std::conditional_t<((sizeof(T0)==sizeof(T1)) &&std::is_unsigned_v< T0 > &&std::is_signed_v< T1 >), T0, T1 > > HigherMax
The type that has the higher max value.
Definition Integral.hpp:29
std::conditional_t<(std::is_unsigned_v< T0 >==std::is_unsigned_v< T1 >), std::conditional_t< std::is_unsigned_v< T0 >, std::conditional_t<(sizeof(T0)< sizeof(T1)), T1, T0 >, std::conditional_t<(sizeof(T0)< sizeof(T1)), T0, T1 > >, std::conditional_t< std::is_unsigned_v< T0 >, T0, T1 > > HigherMin
The type that has the higher min value. If both types have the same min value, the type with the wide...
Definition Integral.hpp:47
std::conditional_t<(std::is_unsigned_v< T0 >==std::is_unsigned_v< T1 >), std::conditional_t<(sizeof(T0) > sizeof(T1)), T0, T1 >, std::conditional_t< std::is_signed_v< T0 >, T0, T1 > > LowerMin
The type that has the lower min value. If both types have the same min value, the type with the wider...
Definition Integral.hpp:55