Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/utils/include/utils/containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "bidict.h"
#include "invoke.h"
#include "optional.h"
#include "type_traits.h"
#include "type_traits_core.h"
#include <algorithm>
#include <cassert>
#include <functional>
Expand Down Expand Up @@ -533,6 +533,17 @@ C filter(C const &v, F const &f) {
return result;
}

template <typename T, typename F>
std::unordered_set<T> filter(std::unordered_set<T> const &v, F const &f) {
std::unordered_set<T> result;
for (T const &t : v) {
if (f(t)) {
result.insert(t);
}
}
return result;
}

template <typename C, typename F, typename Elem = typename C::value_type>
void inplace_filter(C &v, F const &f) {
std::remove_if(v.begin(), v.end(), [&](Elem const &e) { return !f(e); });
Expand Down
10 changes: 0 additions & 10 deletions lib/utils/include/utils/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,6 @@ struct elements_satisfy<Cond, std::tuple<>> : std::true_type {};
static_assert(
elements_satisfy<is_equal_comparable, std::tuple<int, float>>::value, "");

template <typename C, typename Tag>
struct supports_iterator_tag
: std::is_base_of<Tag,
typename std::iterator_traits<
typename C::iterator>::iterator_category> {};

#define CHECK_SUPPORTS_ITERATOR_TAG(TAG, ...) \
static_assert(supports_iterator_tag<__VA_ARGS__, TAG>::value, \
#__VA_ARGS__ " does not support required iterator tag " #TAG);

template <typename T>
using is_default_constructible = std::is_default_constructible<T>;

Expand Down
10 changes: 10 additions & 0 deletions lib/utils/include/utils/type_traits_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ struct is_static_castable<
void_t<decltype(static_cast<To>(std::declval<From>()))>> : std::true_type {
};

template <typename C, typename Tag>
struct supports_iterator_tag
: std::is_base_of<Tag,
typename std::iterator_traits<
typename C::iterator>::iterator_category> {};

#define CHECK_SUPPORTS_ITERATOR_TAG(TAG, ...) \
static_assert(supports_iterator_tag<__VA_ARGS__, TAG>::value, \
#__VA_ARGS__ " does not support required iterator tag " #TAG);

} // namespace FlexFlow

#endif