Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions include/stdx/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,23 @@ struct from_any {
constexpr operator int() const { return 0; }
};

struct value_marker {};

struct type_val {
template <typename T, typename U,
typename = std::enable_if_t<same_as_unqualified<type_val, U>>>
friend constexpr auto operator+(T t, U const &) -> T {
return t;
}
friend constexpr auto operator+(type_val const &f) -> type_val { return f; }

template <typename T, typename U,
typename = std::enable_if_t<same_as_unqualified<type_val, U>>>
friend constexpr auto operator*(T, U const &) -> value_marker {
return {};
}
friend constexpr auto operator*(type_val const &f) -> type_val { return f; }

// NOLINTNEXTLINE(google-explicit-constructor)
template <typename T> constexpr operator T() const {
if constexpr (std::is_default_constructible_v<T>) {
Expand All @@ -164,7 +174,7 @@ struct type_val {
};

template <typename> constexpr inline auto is_type = true;
template <> constexpr inline auto is_type<from_any> = false;
template <> constexpr inline auto is_type<value_marker> = false;

class cx_base {
struct unusable {};
Expand Down Expand Up @@ -226,8 +236,8 @@ template <typename T> constexpr auto is_ct_v<T const> = is_ct_v<T>;

#ifndef STDX_IS_TYPE
#define STDX_IS_TYPE(...) \
::stdx::cxv_detail::is_type<__typeof__(::stdx::cxv_detail::from_any( \
__VA_ARGS__))>
::stdx::cxv_detail::is_type<decltype((__VA_ARGS__) * \
::stdx::cxv_detail::type_val{})>
#endif

#ifndef CX_VALUE
Expand Down