10#include "../macros.hpp"
19hi_export_module(hikogui.utility.type_traits);
177template<
typename T,
typename U>
179 using type =
decltype(
static_cast<T
>(0) +
static_cast<U
>(0));
182template<
typename T,
typename U>
183using make_promote_t =
typename make_promote<T,U>::type;
185template<
typename T,
typename Ei=
void>
187 using type = uintmax_t;
190template<std::
unsigned_
integral T>
192 using type = uintmax_t;
195template<std::
signed_
integral T>
197 using type = intmax_t;
201using make_intmax_t =
typename make_intmax<T>::type;
266template<>
struct make_uintxx<128> {
using type = uint128_t; };
301template<
typename L,
typename... R>
304template<std::
integral T>
309template<std::
unsigned_
integral L, std::
unsigned_
integral R>
311 using type = std::conditional_t<(
sizeof(L) >
sizeof(R)), L, R>;
314template<std::
signed_
integral L, std::
signed_
integral R>
316 using type = std::conditional_t<(
sizeof(L) >
sizeof(R)), L, R>;
319template<std::
unsigned_
integral L, std::
signed_
integral R>
320struct common_integer<L,R> {
322 std::conditional_t<(
sizeof(L) <
sizeof(
short)),
short,
323 std::conditional_t<(
sizeof(L) <
sizeof(int)), int,
324 std::conditional_t<(
sizeof(L) <
sizeof(
long)),
long,
long long>>>;
326 using type = common_integer<_left_type, R>::type;
329template<std::
signed_
integral L, std::
unsigned_
integral R>
330struct common_integer<L,R> {
331 using type = common_integer<R, L>::type;
334template<std::integral L, std::integral M, std::integral... R>
351template<std::integral L, std::integral... R>
355struct remove_cvptr {
using type = std::remove_cv_t<std::remove_pointer_t<T>>; };
358using remove_cvptr_t = remove_cvptr<T>::type;
362template<
typename To,
typename From,
typename Ei=
void>
365template<
typename To,
typename From>
requires(
not std::is_const_v<From>
and not std::is_volatile_v<From>)
367 using type = std::remove_cv_t<To>;
370template<
typename To,
typename From>
requires(
not std::is_const_v<From>
and std::is_volatile_v<From>)
372 using type = std::remove_cv_t<To>
volatile;
375template<
typename To,
typename From>
requires(std::is_const_v<From>
and not std::is_volatile_v<From>)
376struct copy_cv<To,From> {
377 using type = std::remove_cv_t<To>
const;
380template<
typename To,
typename From>
requires(std::is_const_v<From>
and std::is_volatile_v<From>)
381struct copy_cv<To,From> {
382 using type = std::remove_cv_t<To>
const volatile;
387template<
typename To,
typename From>
392 template <
typename C>
static std::true_type test(
typename C::value_type *);
395 static const bool value = std::is_same_v<decltype(test<T>(
nullptr)),
std::true_type>;
403 template <
typename C>
static std::true_type test(
decltype(&C::add_callback) func_ptr);
406 static const bool value = std::is_same_v<decltype(test<T>(
nullptr)),
std::true_type>;
412template<
typename BaseType,
typename DerivedType>
415template<
typename BaseType,
typename DerivedType>
418template<
typename DerivedType,
typename BaseType>
421template<
typename DerivedType,
typename BaseType>
424template<
typename DerivedType,
typename BaseType>
427template<
typename DerivedType,
typename BaseType>
433template<
typename Context,
typename Expected>
434constexpr bool is_different_v =
not std::is_same_v<std::decay_t<Context>,std::decay_t<Expected>>;
445template<
typename First,
typename Second>
450template<
typename First,
typename Second>
462 constexpr static bool value =
false;
481#define hi_call_method(object, method, ...) \
483 if constexpr (smart_pointer_traits<std::decay_t<decltype(object)>>::value) { \
484 return object->method(__VA_ARGS__); \
486 return object.method(__VA_ARGS__); \
492template<
typename Out,
typename In>
538 is_forward_of<Context, Expected>::value or
539 (is_forward_of<Context, FirstOtherExpected>::value or ... or is_forward_of<Context, OtherExpected>::value),
543template<
typename Context,
typename Expected>
546 std::is_same_v<std::decay_t<Context>, Expected> or std::is_base_of_v<Expected, std::decay_t<Context>>,
549 static_assert(not std::is_reference_v<Expected>,
"Template argument Expected must be a non-reference type.");
552template<
typename Context,
typename Expected>
555 std::is_convertible_v<Context, std::shared_ptr<Expected>>,
559template<
typename Context,
typename Expected>
562 std::is_convertible_v<Context, std::weak_ptr<Expected>>,
566template<
typename Context,
typename Expected>
569 std::is_convertible_v<Context, std::unique_ptr<Expected>>,
573template<
typename Context,
typename Expected>
576 std::is_convertible_v<Context, Expected *>,
582 std::conditional_t<std::is_invocable_r_v<Result, Context, Args...>, std::true_type, std::false_type> {
588template<
typename Context>
590 using type = std::conditional_t<std::is_rvalue_reference_v<Context>, std::decay_t<Context>, std::decay_t<Context>
const &>;
593template<
typename Context>
594using forward_copy_or_ref_t = forward_copy_or_ref<Context>::type;
603 using type = std::decay_t<T>;
608 using type = std::monostate;
676 using Ts::operator()...;
689template<std::
integral T>
692 constexpr static T off = T{};
693 constexpr static T on = T{1};
696template<
typename T>
requires (std::is_enum_v<T>)
699 constexpr static T on =
static_cast<T
>(1);
703constexpr bool default_values_v = default_values<T>::value;
DOXYGEN BUG.
Definition algorithm.hpp:16
common_integer< L, R... >::type common_integer_t
Get an integer type that will fit all values from all template parameters.
Definition type_traits.hpp:352
constexpr bool is_numeric_v
Definition type_traits.hpp:113
constexpr bool is_different_v
If the types are different.
Definition type_traits.hpp:434
typename make_string< T >::type make_string_t
type-trait to convert a character to a string type.
Definition type_traits.hpp:161
typename make_string_view< T >::type make_string_view_t
type-trait to convert a character to a string_view type.
Definition type_traits.hpp:175
__int128 int128_t
Signed 128 bit integer.
Definition architecture.hpp:54
constexpr bool is_numeric_unsigned_integral_v
Definition type_traits.hpp:61
variant_decay< T >::type variant_decay_t
Definition type_traits.hpp:614
constexpr bool is_byte_like_v
An array of this type will implicitly create objects within that array.
Definition type_traits.hpp:148
typename copy_cv< To, From >::type copy_cv_t
Type-trait to copy const volatile qualifiers from one type to another.
Definition type_traits.hpp:388
constexpr bool is_numeric_integral_v
Definition type_traits.hpp:85
constexpr bool type_in_range_v
All values of numeric type In can be represented without loss of range by numeric type Out.
Definition type_traits.hpp:493
constexpr bool is_character_v
Definition type_traits.hpp:130
constexpr bool is_numeric_signed_integral_v
Definition type_traits.hpp:42
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Is a numeric signed integer.
Definition type_traits.hpp:32
Is a numeric unsigned integer.
Definition type_traits.hpp:51
Is a numeric integer.
Definition type_traits.hpp:71
Is a numeric.
Definition type_traits.hpp:96
Definition type_traits.hpp:115
An array of this type will implicitly create objects within that array.
Definition type_traits.hpp:136
type-trait to convert a character to a string type.
Definition type_traits.hpp:152
type-trait to convert a character to a string_view type.
Definition type_traits.hpp:165
Definition type_traits.hpp:178
Definition type_traits.hpp:186
Has an signed integer of a specific size, natively supported by the compiler.
Definition type_traits.hpp:206
Has an unsigned integer of a specific size, natively supported by the compiler.
Definition type_traits.hpp:211
Has an float of a specific size, natively supported by the compiler.
Definition type_traits.hpp:216
Has an signed integer of a specific size.
Definition type_traits.hpp:221
Has an unsigned integer of a specific size.
Definition type_traits.hpp:226
Has an float of a specific size.
Definition type_traits.hpp:232
Make an signed integer.
Definition type_traits.hpp:237
Make an unsigned integer.
Definition type_traits.hpp:242
Make an floating point.
Definition type_traits.hpp:247
Get an integer type that will fit all values from all template parameters.
Definition type_traits.hpp:302
Definition type_traits.hpp:355
Type-trait to copy const volatile qualifiers from one type to another.
Definition type_traits.hpp:363
Definition type_traits.hpp:391
Definition type_traits.hpp:402
Definition type_traits.hpp:413
Definition type_traits.hpp:419
Definition type_traits.hpp:425
Definition type_traits.hpp:437
Definition type_traits.hpp:446
Smart pointer traits.
Definition type_traits.hpp:459
void type
The type the pointer points to.
Definition type_traits.hpp:466
Is context a form of the expected type.
Definition type_traits.hpp:534
Definition type_traits.hpp:589
Decays types for use as elements in std::variant.
Definition type_traits.hpp:602
This selector allows access to member variable by name.
Definition type_traits.hpp:645
Documentation of a type.
Definition type_traits.hpp:665
Helper type to turn a set of lambdas into a single overloaded type to pass to std::visit().
Definition type_traits.hpp:674
A type traits for generating default values of a type.
Definition type_traits.hpp:687