Skip to content

Commit

Permalink
fix type casts
Browse files Browse the repository at this point in the history
  • Loading branch information
dey4ss committed Apr 27, 2023
1 parent 504eccf commit 8c2d112
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/lib/all_type_variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ using AllTypeVariant = typename boost::make_variant_over<detail::TypesAsMplVecto
} // namespace detail

static constexpr auto types = detail::types;
static constexpr auto types_including_null = detail::types_including_null;
static constexpr auto data_types = detail::data_types;

using AllTypeVariant = detail::AllTypeVariant;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/type_cast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ constexpr auto index_of(Sequence const& sequence, T const& element) {
// Retrieves the value stored in an AllTypeVariant without conversion
template <typename T>
const T& get(const AllTypeVariant& value) {
static_assert(hana::contains(types, hana::type_c<T>), "Type not in AllTypeVariant");
static_assert(hana::contains(types_including_null, hana::type_c<T>), "Type not in AllTypeVariant");
return boost::get<T>(value);
}

Expand All @@ -36,7 +36,7 @@ const T& get(const AllTypeVariant& value) {
// Template specialization for everything but integral types
template <typename T>
std::enable_if_t<!std::is_integral<T>::value, T> type_cast(const AllTypeVariant& value) {
if (static_cast<size_t>(value.which()) == detail::index_of(types, hana::type_c<T>)) {
if (static_cast<size_t>(value.which()) == detail::index_of(types_including_null, hana::type_c<T>)) {
return get<T>(value);
}

Expand All @@ -46,7 +46,7 @@ std::enable_if_t<!std::is_integral<T>::value, T> type_cast(const AllTypeVariant&
// Template specialization for integral types
template <typename T>
std::enable_if_t<std::is_integral<T>::value, T> type_cast(const AllTypeVariant& value) {
if (static_cast<size_t>(value.which()) == detail::index_of(types, hana::type_c<T>)) {
if (static_cast<size_t>(value.which()) == detail::index_of(types_including_null, hana::type_c<T>)) {
return get<T>(value);
}

Expand Down

0 comments on commit 8c2d112

Please sign in to comment.