Skip to content

Commit

Permalink
Update optional
Browse files Browse the repository at this point in the history
  • Loading branch information
lackhole committed Jun 16, 2024
1 parent 237d480 commit f8e24c4
Show file tree
Hide file tree
Showing 11 changed files with 443 additions and 674 deletions.
40 changes: 34 additions & 6 deletions include/preview/__optional/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,47 @@
# include <functional>
# include <type_traits>
#
# include "preview/__optional/internal/hash.h"
# include "preview/__optional/optional.h"

namespace preview {
namespace detail {

template<typename Optional>
struct optional_enabled_hash;

template<typename T>
struct optional_enabled_hash<optional<T>> {
std::size_t operator()(const optional<T>& key) const noexcept {
return key.has_value() ? std::hash<std::remove_const_t<T>>()(*key) : 0;
}
};

struct optional_disabled_hash {
optional_disabled_hash() = delete;
};

template<typename Optional>
struct optional_hash;

template<typename T>
struct optional_hash<optional<T>>
: std::conditional_t<
std::is_default_constructible<std::hash<T>>::value,
optional_enabled_hash<optional<T>>,
optional_disabled_hash
> {};

} // namespace detail
} // namespace preview

namespace std {

template<typename T>
struct hash<preview::optional<T>> : preview::internal::optional::hash_constructible<std::remove_const_t<T>> {
struct hash<preview::optional<T>>
: preview::detail::optional_hash<preview::optional<T>>
{
using argument_type = preview::optional<T>;
using result_type = std::size_t;

result_type operator()(const argument_type& key) const {
return key.has_value() ? ::std::hash<std::remove_const_t<T>>()(*key) : 0;
}
};

} // namespace std
Expand Down
66 changes: 0 additions & 66 deletions include/preview/__optional/internal/check_overload.h

This file was deleted.

51 changes: 0 additions & 51 deletions include/preview/__optional/internal/copy_assignment.h

This file was deleted.

43 changes: 0 additions & 43 deletions include/preview/__optional/internal/copy_ctor.h

This file was deleted.

122 changes: 0 additions & 122 deletions include/preview/__optional/internal/dtor.h

This file was deleted.

32 changes: 0 additions & 32 deletions include/preview/__optional/internal/hash.h

This file was deleted.

Loading

0 comments on commit f8e24c4

Please sign in to comment.