Skip to content

Commit

Permalink
Strenghten sat attrs ref
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoinePrv committed Dec 28, 2023
1 parent 73eb02e commit 0315574
Showing 1 changed file with 45 additions and 24 deletions.
69 changes: 45 additions & 24 deletions libmamba/src/core/satisfiability_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace mamba

std::vector<old_node_id_list> groups{};

std::size_t const n_nodes = node_indices.size();
const std::size_t n_nodes = node_indices.size();
std::vector<bool> node_added_to_a_group(n_nodes, false);
for (std::size_t i = 0; i < n_nodes; ++i)
{
Expand Down Expand Up @@ -538,14 +538,45 @@ namespace mamba
* Implementation of CompressedProblemsGraph::RoughCompare *
*************************************************************/

namespace
{
template <typename T>
auto invoke_name(T&& e) -> decltype(auto)
{
using TT = std::remove_cv_t<std::remove_reference_t<T>>;
return std::invoke(&TT::name, std::forward<T>(e));
}

template <typename T>
auto invoke_version(T&& e) -> decltype(auto)
{
using TT = std::remove_cv_t<std::remove_reference_t<T>>;
using Ver = decltype(std::invoke(&TT::version, std::forward<T>(e)));
Ver v = std::invoke(&TT::version, std::forward<T>(e));
if constexpr (std::is_same_v<std::decay_t<decltype(v)>, specs::VersionSpec>)
{
return std::forward<Ver>(v).str();
}
else
{
return v;
}
}
}

template <typename T>
bool CompressedProblemsGraph::RoughCompare<T>::operator()(const T& a, const T& b) const
auto CompressedProblemsGraph::RoughCompare<T>::operator()(const T& a, const T& b) const -> bool
{
auto attrs = [](const auto& x)
{
return std::tie(
std::invoke(&T::name, x),
std::invoke(&T::version, x),
using Attrs = std::tuple<
decltype(invoke_name(x)),
decltype(invoke_version(x)),
decltype(std::invoke(&T::build_number, x)),
decltype(std::invoke(&T::build_string, x))>;
return Attrs(
invoke_name(x),
invoke_version(x),
std::invoke(&T::build_number, x),
std::invoke(&T::build_string, x)
);
Expand All @@ -562,16 +593,6 @@ namespace mamba
* Implementation of CompressedProblemsGraph::NamedList *
**********************************************************/

namespace
{
template <typename T>
decltype(auto) invoke_name(T&& e)
{
using TT = std::remove_cv_t<std::remove_reference_t<T>>;
return std::invoke(&TT::name, std::forward<T>(e));
}
}

template <typename T, typename A>
template <typename InputIterator>
CompressedProblemsGraph::NamedList<T, A>::NamedList(InputIterator first, InputIterator last)
Expand Down Expand Up @@ -650,13 +671,13 @@ namespace mamba
) const -> std::pair<std::string, std::size_t>
{
auto versions = std::vector<std::string>(size());
auto invoke_version = [](auto&& v) -> decltype(auto)
{
using TT = std::remove_cv_t<std::remove_reference_t<decltype(v)>>;
return std::invoke(&TT::version, std::forward<decltype(v)>(v));
};
// TODO(C++20) *this | std::ranges::transform(invoke_version) | ranges::unique
std::transform(begin(), end(), versions.begin(), invoke_version);
std::transform(
begin(),
end(),
versions.begin(),
[](const auto& x) { return invoke_version(x); }
);
if (remove_duplicates)
{
versions.erase(std::unique(versions.begin(), versions.end()), versions.end());
Expand Down Expand Up @@ -1036,7 +1057,7 @@ namespace mamba

const TreeNodeIter children_begin = out;
// TODO(C++20) an enumerate view ``views::zip(views::iota(), children_ids)``
std::size_t const n_children = children_ids.size();
const std::size_t n_children = children_ids.size();
for (std::size_t i = 0; i < n_children; ++i)
{
const bool last = (i == n_children - 1);
Expand Down Expand Up @@ -1228,7 +1249,7 @@ namespace mamba

void TreeExplainer::write_ancestry(const std::vector<SiblingNumber>& ancestry)
{
std::size_t const size = ancestry.size();
const std::size_t size = ancestry.size();
const auto indents = m_format.indents;
if (size > 0)
{
Expand Down Expand Up @@ -1434,7 +1455,7 @@ namespace mamba

void TreeExplainer::write_path(const std::vector<TreeNode>& path)
{
std::size_t const length = path.size();
const std::size_t length = path.size();
for (std::size_t i = 0; i < length; ++i)
{
const bool last = (i == length - 1);
Expand Down

0 comments on commit 0315574

Please sign in to comment.