Skip to content

Commit

Permalink
Merge pull request GUDHI#1125 from hschreiber/persistence_interval_st…
Browse files Browse the repository at this point in the history
…ructural_bindings_fix

[Persistence Interval] fix of structural binding bug in windows compiler
  • Loading branch information
VincentRouvreau authored Aug 27, 2024
2 parents 28764ab + c1aaa79 commit 9aa70a7
Showing 1 changed file with 99 additions and 75 deletions.
174 changes: 99 additions & 75 deletions src/Persistence_matrix/include/gudhi/persistence_interval.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,140 +88,164 @@ struct Persistence_interval {
}
return stream;
}

/**
* @brief Specialization of `get` for @ref Gudhi::persistence_matrix::Persistence_interval.
*
* @tparam I Index of the value to return: 0 for the birth value, 1 for the death value and 2 for the dimension.
* @return Either the birth value if @p I == 0, the death value if @p I == 1 or the dimension if @p I == 2.
*/
template <std::size_t I>
constexpr auto& get() & noexcept {
static_assert(I < 3, "Value mismatch at argument 1 in template parameter list. Maximal possible value is 2.");

if constexpr (I == 0) return birth;
if constexpr (I == 1) return death;
if constexpr (I == 2) return dim;
}

/**
* @brief Specialization of `get` for @ref Gudhi::persistence_matrix::Persistence_interval.
*
* @tparam I Index of the value to return: 0 for the birth value, 1 for the death value and 2 for the dimension.
* @return Either the birth value if @p I == 0, the death value if @p I == 1 or the dimension if @p I == 2.
*/
template <std::size_t I>
constexpr const auto& get() const& noexcept {
static_assert(I < 3, "Value mismatch at argument 1 in template parameter list. Maximal possible value is 2.");

if constexpr (I == 0) return birth;
if constexpr (I == 1) return death;
if constexpr (I == 2) return dim;
}

/**
* @brief Specialization of `get` for @ref Gudhi::persistence_matrix::Persistence_interval.
*
* @tparam I Index of the value to return: 0 for the birth value, 1 for the death value and 2 for the dimension.
* @return Either the birth value if @p I == 0, the death value if @p I == 1 or the dimension if @p I == 2.
*/
template <std::size_t I>
constexpr auto&& get() && noexcept {
static_assert(I < 3, "Value mismatch at argument 1 in template parameter list. Maximal possible value is 2.");

if constexpr (I == 0) return std::move(birth);
if constexpr (I == 1) return std::move(death);
if constexpr (I == 2) return std::move(dim);
}

/**
* @brief Specialization of `get` for @ref Gudhi::persistence_matrix::Persistence_interval.
*
* @tparam I Index of the value to return: 0 for the birth value, 1 for the death value and 2 for the dimension.
* @return Either the birth value if @p I == 0, the death value if @p I == 1 or the dimension if @p I == 2.
*/
template <std::size_t I>
constexpr const auto&& get() const&& noexcept {
static_assert(I < 3, "Value mismatch at argument 1 in template parameter list. Maximal possible value is 2.");

if constexpr (I == 0) return std::move(birth);
if constexpr (I == 1) return std::move(death);
if constexpr (I == 2) return std::move(dim);
}
};

} // namespace persistence_matrix
} // namespace Gudhi

namespace std {

/**
* @ingroup persistence_matrix
*
* @brief Partial specialization of `get` for @ref Gudhi::persistence_matrix::Persistence_interval.
* @brief Partial specialization of `std::tuple_size` for @ref Gudhi::persistence_matrix::Persistence_interval.
*
* @tparam I Index of the value to return: 0 for the birth value, 1 for the death value and 2 for the dimension.
* @tparam Dimension First template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
* @tparam Event_value Second template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
* @param i Interval from which the value should be returned.
* @return Either the birth value if @p I == 0, the death value if @p I == 1 or the dimension if @p I == 2.
*/
template <std::size_t I, typename Dimension, typename Event_value>
constexpr auto& get(Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value>& i) noexcept {
static_assert(I < 3, "Value mismatch at argument 1 in template parameter list. Maximal possible value is 2.");

if constexpr (I == 0) return i.birth;
if constexpr (I == 1) return i.death;
if constexpr (I == 2) return i.dim;
}
template <typename Dimension, typename Event_value>
struct tuple_size<Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value> >
: integral_constant<size_t, 3> {};

/**
* @ingroup persistence_matrix
*
* @brief Partial specialization of `get` for @ref Gudhi::persistence_matrix::Persistence_interval.
* @brief Partial specialization of `std::tuple_element` for @ref Gudhi::persistence_matrix::Persistence_interval.
*
* @tparam I Index of the value to return: 0 for the birth value, 1 for the death value and 2 for the dimension.
* @tparam I Index of the type to store: 0 for the birth value type, 1 for the death value type and 2 for the
* dimension value type.
* @tparam Dimension First template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
* @tparam Event_value Second template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
* @param i Interval from which the value should be returned.
* @return Either the birth value if @p I == 0, the death value if @p I == 1 or the dimension if @p I == 2.
*/
template <std::size_t I, typename Dimension, typename Event_value>
constexpr const auto& get(const Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value>& i) noexcept {
template <size_t I, typename Dimension, typename Event_value>
struct tuple_element<I, Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value> > {
static_assert(I < 3, "Value mismatch at argument 1 in template parameter list. Maximal possible value is 2.");

if constexpr (I == 0) return i.birth;
if constexpr (I == 1) return i.death;
if constexpr (I == 2) return i.dim;
}
using type = typename conditional <I < 2, Event_value, Dimension>::type;
};

/**
* @ingroup persistence_matrix
*
* @brief Partial specialization of `get` for @ref Gudhi::persistence_matrix::Persistence_interval.
*
*
* @tparam I Index of the value to return: 0 for the birth value, 1 for the death value and 2 for the dimension.
* @tparam Dimension First template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
* @tparam Event_value Second template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
* @param i Interval from which the value should be returned.
* @return Either the birth value if @p I == 0, the death value if @p I == 1 or the dimension if @p I == 2.
*/
template <std::size_t I, typename Dimension, typename Event_value>
constexpr auto&& get(Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value>&& i) noexcept {
static_assert(I < 3, "Value mismatch at argument 1 in template parameter list. Maximal possible value is 2.");

if constexpr (I == 0) return std::move(i.birth);
if constexpr (I == 1) return std::move(i.death);
if constexpr (I == 2) return std::move(i.dim);
template <size_t I, typename Dimension, typename Event_value>
constexpr auto& get(Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value>& i) noexcept {
return i.template get<I>();
}

/**
* @ingroup persistence_matrix
*
* @brief Partial specialization of `get` for @ref Gudhi::persistence_matrix::Persistence_interval.
*
*
* @tparam I Index of the value to return: 0 for the birth value, 1 for the death value and 2 for the dimension.
* @tparam Dimension First template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
* @tparam Event_value Second template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
* @param i Interval from which the value should be returned.
* @return Either the birth value if @p I == 0, the death value if @p I == 1 or the dimension if @p I == 2.
*/
template <std::size_t I, typename Dimension, typename Event_value>
constexpr const auto&& get(const Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value>&& i) noexcept {
static_assert(I < 3, "Value mismatch at argument 1 in template parameter list. Maximal possible value is 2.");

if constexpr (I == 0) return std::move(i.birth);
if constexpr (I == 1) return std::move(i.death);
if constexpr (I == 2) return std::move(i.dim);
template <size_t I, typename Dimension, typename Event_value>
constexpr const auto& get(const Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value>& i) noexcept {
return i.template get<I>();
}

} // namespace persistence_matrix
} // namespace Gudhi

namespace std {

/**
* @ingroup persistence_matrix
*
* @brief Partial specialization of `std::tuple_size` for @ref Gudhi::persistence_matrix::Persistence_interval.
*
* @brief Partial specialization of `get` for @ref Gudhi::persistence_matrix::Persistence_interval.
*
* @tparam I Index of the value to return: 0 for the birth value, 1 for the death value and 2 for the dimension.
* @tparam Dimension First template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
* @tparam Event_value Second template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
* @param i Interval from which the value should be returned.
* @return Either the birth value if @p I == 0, the death value if @p I == 1 or the dimension if @p I == 2.
*/
template <typename Dimension, typename Event_value>
struct tuple_size<Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value> >
: integral_constant<size_t, 3> {};
template <size_t I, typename Dimension, typename Event_value>
constexpr auto&& get(Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value>&& i) noexcept {
return std::move(i).template get<I>();
}

/**
* @ingroup persistence_matrix
*
* @brief Partial specialization of `std::tuple_element` for @ref Gudhi::persistence_matrix::Persistence_interval.
*
* @tparam I Index of the type to store: 0 for the birth value type, 1 for the death value type and 2 for the
* dimension value type.
* @brief Partial specialization of `get` for @ref Gudhi::persistence_matrix::Persistence_interval.
*
* @tparam I Index of the value to return: 0 for the birth value, 1 for the death value and 2 for the dimension.
* @tparam Dimension First template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
* @tparam Event_value Second template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
* @param i Interval from which the value should be returned.
* @return Either the birth value if @p I == 0, the death value if @p I == 1 or the dimension if @p I == 2.
*/
template <size_t I, typename Dimension, typename Event_value>
struct tuple_element<I, Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value> > {
static_assert(I < 3, "Value mismatch at argument 1 in template parameter list. Maximal possible value is 2.");

using type = typename conditional <I < 2, Event_value, Dimension>::type;
};

template <size_t I, typename Dimension, typename Event_value>
constexpr auto& get(Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value>& i) noexcept {
return Gudhi::persistence_matrix::get<I>(i);
}

template <size_t I, typename Dimension, typename Event_value>
constexpr const auto& get(const Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value>& i) noexcept {
return Gudhi::persistence_matrix::get<I>(i);
}

template <size_t I, typename Dimension, typename Event_value>
constexpr auto&& get(Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value>&& i) noexcept {
return Gudhi::persistence_matrix::get<I>(move(i));
}

template <size_t I, typename Dimension, typename Event_value>
constexpr const auto&& get(const Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value>&& i) noexcept {
return Gudhi::persistence_matrix::get<I>(move(i));
return std::move(i).template get<I>();
}

} // namespace std
Expand Down

0 comments on commit 9aa70a7

Please sign in to comment.