Merge branch 'smart_range_improvement' into 'master'
Smart range improvement See merge request OpenMesh/OpenMesh!236
This commit is contained in:
@@ -45,6 +45,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
//== NAMESPACES ===============================================================
|
//== NAMESPACES ===============================================================
|
||||||
|
|
||||||
@@ -189,6 +190,41 @@ struct SmartRangeT
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief Convert range to set.
|
||||||
|
*
|
||||||
|
* Converts the range of elements into a set of objects returned by functor \p f.
|
||||||
|
*
|
||||||
|
* @param f Functor that is applied to all elements before putting them into the set. If no functor is provided
|
||||||
|
* the set will contain the handles.
|
||||||
|
*/
|
||||||
|
template <typename Functor = Identity>
|
||||||
|
auto to_set(Functor&& f = {}) -> std::set<typename std::remove_reference<decltype (f(std::declval<HandleT>()))>::type>
|
||||||
|
{
|
||||||
|
auto range = static_cast<const RangeT*>(this);
|
||||||
|
std::set<typename std::remove_reference<decltype (f(std::declval<HandleT>()))>::type> res;
|
||||||
|
for (const auto& e : *range)
|
||||||
|
res.insert(f(e));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief Get the first element that fulfills a condition.
|
||||||
|
*
|
||||||
|
* Finds the first element of the range for which the functor \p f evaluates to true.
|
||||||
|
* Returns an invalid handle if none evaluates to true
|
||||||
|
*
|
||||||
|
* @param f Functor that is applied to all elements before putting them into the set. If no functor is provided
|
||||||
|
* the set will contain the handles.
|
||||||
|
*/
|
||||||
|
template <typename Functor>
|
||||||
|
auto first(Functor&& f = {}) -> HandleT
|
||||||
|
{
|
||||||
|
auto range = static_cast<const RangeT*>(this);
|
||||||
|
for (const auto& e : *range)
|
||||||
|
if (f(e))
|
||||||
|
return e;
|
||||||
|
return HandleT();
|
||||||
|
}
|
||||||
|
|
||||||
/** @brief Compute minimum.
|
/** @brief Compute minimum.
|
||||||
*
|
*
|
||||||
* Computes the minimum of all objects returned by functor \p f.
|
* Computes the minimum of all objects returned by functor \p f.
|
||||||
|
|||||||
Reference in New Issue
Block a user