Skip to content

Commit

Permalink
msvc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marzer committed Aug 18, 2023
1 parent 5d9c2ad commit ace2252
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 142 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
- Added `soagen::for_each_column()`
- Added `row::for_each_column()`
- Added generic names `first`, `second`, ..., `sixteenth` for unnamed columns 0-15
- Added const propagation to `soagen::row` member functions
- Binary size improvements
- Documentation improvements

Expand Down
8 changes: 4 additions & 4 deletions src/soagen/hpp/iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ namespace soagen
SOAGEN_ASSUME(!!base::table);
SOAGEN_ASSUME(base::offset >= 0);

return row_type{ { static_cast<value_ref<Soa, Columns>>(
base::table->template column<Columns>()[base::offset]) }... };
return row_type{ static_cast<value_ref<Soa, Columns>>(
base::table->template column<Columns>()[base::offset])... };
}

/// @brief Returns the row the iterator refers to.
Expand All @@ -240,8 +240,8 @@ namespace soagen
SOAGEN_ASSUME(!!base::table);
SOAGEN_ASSUME(base::offset + offset >= 0);

return row_type{ { static_cast<value_ref<Soa, Columns>>(
base::table->template column<Columns>()[base::offset + offset]) }... };
return row_type{ static_cast<value_ref<Soa, Columns>>(
base::table->template column<Columns>()[base::offset + offset])... };
}

/// @}
Expand Down
26 changes: 13 additions & 13 deletions src/soagen/hpp/mixins/rows.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ namespace soagen::mixins
{
if constexpr (sizeof...(Cols))
{
return { { static_cast<value_ref<Derived&, Cols>>(
static_cast<Derived&>(*this).template column<static_cast<size_type>(Cols)>()[index]) }... };
return { static_cast<value_ref<Derived, Cols>>(
static_cast<Derived&>(*this).template column<static_cast<size_type>(Cols)>()[index])... };
}
else
{
return { { static_cast<value_ref<Derived&, Columns>>(
static_cast<Derived&>(*this).template column<static_cast<size_type>(Columns)>()[index]) }... };
return { static_cast<value_ref<Derived, Columns>>(
static_cast<Derived&>(*this).template column<static_cast<size_type>(Columns)>()[index])... };
}
}

Expand All @@ -47,31 +47,31 @@ namespace soagen::mixins
{
if constexpr (sizeof...(Cols))
{
return { { static_cast<value_ref<Derived&&, Cols>>(
static_cast<Derived&&>(*this).template column<static_cast<size_type>(Cols)>()[index]) }... };
return { static_cast<value_ref<Derived&&, Cols>>(
static_cast<Derived&&>(*this).template column<static_cast<size_type>(Cols)>()[index])... };
}
else
{
return { { static_cast<value_ref<Derived&&, Columns>>(
static_cast<Derived&&>(*this).template column<static_cast<size_type>(Columns)>()[index]) }... };
return { static_cast<value_ref<Derived&&, Columns>>(
static_cast<Derived&&>(*this).template column<static_cast<size_type>(Columns)>()[index])... };
}
}

template <auto... Cols>
SOAGEN_PURE_GETTER
SOAGEN_CPP20_CONSTEXPR
soagen::row_type<const Derived, Cols...> row(size_type index) const& noexcept
soagen::const_row_type<Derived, Cols...> row(size_type index) const& noexcept
{
if constexpr (sizeof...(Cols))
{
return { { static_cast<value_ref<const Derived&, Cols>>(
static_cast<const Derived&>(*this).template column<static_cast<size_type>(Cols)>()[index]) }... };
return { static_cast<value_ref<const Derived, Cols>>(
static_cast<const Derived&>(*this).template column<static_cast<size_type>(Cols)>()[index])... };
}
else
{
return { { static_cast<value_ref<const Derived&, Columns>>(
return { static_cast<value_ref<const Derived, Columns>>(
static_cast<const Derived&>(*this)
.template column<static_cast<size_type>(Columns)>()[index]) }... };
.template column<static_cast<size_type>(Columns)>()[index])... };
}
}

Expand Down
28 changes: 9 additions & 19 deletions src/soagen/hpp/names.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,10 @@
\
protected: \
SOAGEN_PURE_INLINE_GETTER \
constexpr T get_ref() noexcept \
constexpr T get_ref() const noexcept \
{ \
return static_cast<T>(Name); \
} \
SOAGEN_PURE_INLINE_GETTER \
constexpr decltype(auto) get_ref() const noexcept \
{ \
return static_cast<copy_ref<std::add_const_t<std::remove_reference_t<T>>, T>>(Name); \
} \
}; \
\
template <typename Derived, size_t Column> \
Expand Down Expand Up @@ -113,17 +108,11 @@ namespace soagen::detail
T val_;

SOAGEN_PURE_INLINE_GETTER
constexpr T get_ref() noexcept
constexpr T get_ref() const noexcept
{
return static_cast<T>(val_);
}

SOAGEN_PURE_INLINE_GETTER
constexpr decltype(auto) get_ref() const noexcept
{
return static_cast<copy_ref<std::add_const_t<std::remove_reference_t<T>>, T>>(val_);
}

public:
template <typename Val>
SOAGEN_NODISCARD_CTOR
Expand Down Expand Up @@ -179,19 +168,20 @@ namespace soagen::detail

//--- column references ---------

template <typename Derived, size_t Column>
struct SOAGEN_EMPTY_BASES column_ref : named_ref<column_name_tag<Derived, Column>, value_ref<Derived, Column>>
template <typename Soa, size_t Column>
struct SOAGEN_EMPTY_BASES column_ref //
: named_ref<column_name_tag<Soa, Column>, value_ref<Soa, Column>>
{
static_assert(!std::is_lvalue_reference_v<Derived>);
static_assert(!std::is_lvalue_reference_v<Soa>);
};

//--- column functions ---------

template <typename Derived, size_t Column>
template <typename Soa, size_t Column>
struct SOAGEN_EMPTY_BASES column_func //
: named_func<column_name_tag<Derived, Column>, Derived, Column>
: named_func<column_name_tag<Soa, Column>, Soa, Column>
{
static_assert(!is_cvref<Derived>);
static_assert(!is_cvref<Soa>);
};
}
/// @endcond
Expand Down
60 changes: 24 additions & 36 deletions src/soagen/hpp/row.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,23 @@ namespace soagen
"row_base specializations may not have data members");
static_assert(std::is_trivial_v<row_base<row<Soa, Columns...>>>, "row_base specializations must be trivial");

/// @cond

SOAGEN_NODISCARD_CTOR
constexpr row(value_ref<Soa, Columns>... args) noexcept //
: detail::column_ref<Soa, Columns>{ static_cast<value_ref<Soa, Columns>>(args) }...
{}

SOAGEN_DEFAULT_RULE_OF_FIVE(row);

/// @endcond

/// @name Columns
/// @{

/// @brief Returns a reference to the specified column's value.
template <auto Column>
SOAGEN_PURE_INLINE_GETTER
constexpr decltype(auto) column() noexcept
{
static_assert(static_cast<size_t>(Column) < table_traits_type<Soa>::column_count,
"column index out of range");

return detail::column_ref<Soa, static_cast<size_t>(Column)>::get_ref();
}

/// @brief Returns a reference to the specified column's value (const overload).
template <auto Column>
SOAGEN_PURE_INLINE_GETTER
constexpr decltype(auto) column() const noexcept
{
static_assert(static_cast<size_t>(Column) < table_traits_type<Soa>::column_count,
Expand All @@ -174,16 +174,6 @@ namespace soagen
/// @see soagen::for_each_column
template <typename Func>
SOAGEN_ALWAYS_INLINE
constexpr void for_each_column(Func&& func) //
noexcept(noexcept(soagen::for_each_column(std::declval<row&>(), std::declval<Func&&>())))
{
soagen::for_each_column(*this, static_cast<Func&&>(func));
}

/// @brief Invokes a callable once for each column in the row (const overload).
/// @see soagen::for_each_column
template <typename Func>
SOAGEN_ALWAYS_INLINE
constexpr void for_each_column(Func&& func) const //
noexcept(noexcept(soagen::for_each_column(std::declval<const row&>(), std::declval<Func&&>())))
{
Expand All @@ -199,17 +189,6 @@ namespace soagen
/// @note `Member` corresponds to the column at the specified position of the `Columns` template argument.
template <auto Member>
SOAGEN_PURE_INLINE_GETTER
constexpr decltype(auto) get() noexcept
{
static_assert(Member < sizeof...(Columns), "member index out of range");

return type_at_index<static_cast<size_t>(Member), detail::column_ref<Soa, Columns>...>::get_ref();
}

/// @brief Returns a reference to the specified member's value (const overload).
/// @note `Member` corresponds to the column at the specified position of the `Columns` template argument.
template <auto Member>
SOAGEN_PURE_INLINE_GETTER
constexpr decltype(auto) get() const noexcept
{
static_assert(Member < sizeof...(Columns), "member index out of range");
Expand All @@ -230,6 +209,11 @@ namespace soagen
friend constexpr bool operator==(const row& lhs, const row<T, Columns...>& rhs) //
noexcept(table_traits_type<Soa>::all_nothrow_equality_comparable)
{
if constexpr (std::is_same_v<Soa, T>)
{
if (&lhs == &rhs)
return true;
}
return ((lhs.template column<Columns>() == rhs.template column<Columns>()) && ...);
}

Expand Down Expand Up @@ -257,6 +241,12 @@ namespace soagen
static constexpr int row_compare_impl(const row& lhs, const row<T, Columns...>& rhs) //
noexcept(table_traits_type<Soa>::all_nothrow_less_than_comparable)
{
if constexpr (std::is_same_v<Soa, T>)
{
if (&lhs == &rhs)
return 0;
}

if (lhs.template get<Member>() < rhs.template get<Member>())
return -1;

Expand Down Expand Up @@ -341,8 +331,7 @@ namespace soagen
SOAGEN_PURE_INLINE_GETTER
constexpr operator row<T, Cols...>() const noexcept
{
return row<T, Cols...>{ { static_cast<decltype(std::declval<row<T, Cols...>>().template column<Cols>())>(
this->template column<Cols>()) }... };
return row<T, Cols...>{ static_cast<value_ref<T, Cols>>(this->template column<Cols>())... };
}

/// @cond
Expand All @@ -354,8 +343,7 @@ namespace soagen
SOAGEN_PURE_INLINE_GETTER
explicit constexpr operator row<T, Cols...>() const noexcept
{
return row<T, Cols...>{ { static_cast<decltype(std::declval<row<T, Cols...>>().template column<Cols>())>(
this->template column<Cols>()) }... };
return row<T, Cols...>{ static_cast<value_ref<T, Cols>>(this->template column<Cols>())... };
}

/// @endcond
Expand Down
Loading

0 comments on commit ace2252

Please sign in to comment.