libpressio 0.93.0
Loading...
Searching...
No Matches
dtype.h
Go to the documentation of this file.
1#ifndef LIBPRESSIO_DTYPE_CPP
2#define LIBPRESSIO_DTYPE_CPP
3#include <pressio_dtype.h>
4#include <std_compat/type_traits.h>
5#include <cstdint>
6#include <stdint.h>
7
13namespace impl {
14 template <class T, class... Ts>
15 struct is_one_of : public compat::disjunction<std::is_same<T,Ts>...> {
16 };
17}
18
23 static_assert(sizeof(size_t) <= 8, "unexpected type");
24 return (
25 (sizeof(size_t) == 8 && std::is_unsigned<size_t>::value) ? pressio_uint64_dtype :
26 (sizeof(size_t) == 8 && !std::is_unsigned<size_t>::value) ? pressio_int64_dtype :
27 (sizeof(size_t) == 4 && std::is_unsigned<size_t>::value) ? pressio_uint32_dtype :
28 (sizeof(size_t) == 4 && !std::is_unsigned<size_t>::value) ? pressio_int32_dtype :
29 (sizeof(size_t) == 2 && std::is_unsigned<size_t>::value) ? pressio_uint16_dtype :
30 (sizeof(size_t) == 2 && !std::is_unsigned<size_t>::value) ? pressio_int16_dtype :
32 );
33}
34
41template <class T>
44 "unexpected type");
45 return (std::is_same<T, double>::value ? pressio_double_dtype :
46 std::is_same<T, float>::value ? pressio_float_dtype :
47 std::is_same<T, int64_t>::value ? pressio_int64_dtype :
48 std::is_same<T, int32_t>::value ? pressio_int32_dtype :
49 std::is_same<T, int16_t>::value ? pressio_int16_dtype :
50 std::is_same<T, int8_t>::value ? pressio_int8_dtype :
51 std::is_same<T, size_t>::value ? pressio_size_type() :
52 std::is_same<T, uint64_t>::value ? pressio_uint64_dtype :
53 std::is_same<T, uint32_t>::value ? pressio_uint32_dtype :
54 std::is_same<T, uint16_t>::value ? pressio_uint16_dtype :
55 std::is_same<T, uint8_t>::value ? pressio_uint8_dtype :
56 std::is_same<T, bool>::value ? pressio_bool_dtype :
58 );
59}
60
61#endif /* end of include guard: LIBPRESSIO_DTYPE_CPP */
constexpr pressio_dtype pressio_dtype_from_type()
Definition: dtype.h:42
constexpr pressio_dtype pressio_size_type()
Definition: dtype.h:22
Information on types used by libpressio.
pressio_dtype
Definition: pressio_dtype.h:16
@ pressio_byte_dtype
Definition: pressio_dtype.h:27
@ pressio_bool_dtype
Definition: pressio_dtype.h:28
@ pressio_double_dtype
Definition: pressio_dtype.h:17
@ pressio_int16_dtype
Definition: pressio_dtype.h:24
@ pressio_uint64_dtype
Definition: pressio_dtype.h:22
@ pressio_float_dtype
Definition: pressio_dtype.h:18
@ pressio_uint16_dtype
Definition: pressio_dtype.h:20
@ pressio_int64_dtype
Definition: pressio_dtype.h:26
@ pressio_int8_dtype
Definition: pressio_dtype.h:23
@ pressio_uint8_dtype
Definition: pressio_dtype.h:19
@ pressio_uint32_dtype
Definition: pressio_dtype.h:21
@ pressio_int32_dtype
Definition: pressio_dtype.h:25
Definition: dtype.h:15