Skip to content

Commit 1212e8f

Browse files
committed
Add deduction guides for type aliases in prelude
1 parent 31ffbb7 commit 1212e8f

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

include/kernel_float/constant.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ struct constant {
2828
T value_;
2929
};
3030

31+
// Deduction guide for `constant<T>`
32+
#if defined(__cpp_deduction_guides)
33+
template<typename T>
34+
constant(T&&) -> constant<decay_t<T>>;
35+
#endif
36+
3137
template<typename T = double>
3238
KERNEL_FLOAT_INLINE constexpr constant<T> make_constant(T value) {
3339
return value;

include/kernel_float/prelude.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#ifndef KERNEL_FLOAT_PRELUDE_H
22
#define KERNEL_FLOAT_PRELUDE_H
33

4+
#include "bf16.h"
45
#include "constant.h"
6+
#include "fp16.h"
57
#include "vector.h"
68

79
namespace kernel_float {
@@ -94,6 +96,18 @@ static constexpr kconstant<long long int> operator""_c(unsigned long long int v)
9496
return static_cast<long long int>(v);
9597
}
9698

99+
// Deduction guides for aliases are only supported from C++20
100+
#if defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201907L
101+
template<typename T>
102+
kscalar(T&&) -> kscalar<decay_t<T>>;
103+
104+
template<typename... Args>
105+
kvec(Args&&...) -> kvec<promote_t<Args...>, sizeof...(Args)>;
106+
107+
template<typename T>
108+
kconstant(T&&) -> kconstant<decay_t<T>>;
109+
#endif
110+
97111
} // namespace prelude
98112
} // namespace kernel_float
99113

0 commit comments

Comments
 (0)