Skip to content

Commit

Permalink
libcore: Mapping a container to a different type of container
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent f2bd67b commit f11fdc2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion doomsday/libs/core/include/de/data/string.h
Expand Up @@ -443,7 +443,7 @@ class DENG2_PUBLIC String : public QString
static void advanceFormat(String::const_iterator &i,
String::const_iterator const &end);

static String join(QList<String> const &stringList, String const &sep = String());
static String join(QList<String> const &stringList, String const &sep = {});
};

/**
Expand Down
11 changes: 11 additions & 0 deletions doomsday/libs/core/include/de/libcore.h
Expand Up @@ -650,6 +650,17 @@ inline OutContainer map(const InContainer &input, Func func) {
return out;
}

template <typename OutContainer, typename InContainer>
inline OutContainer map(const InContainer &input,
std::function<typename OutContainer::value_type (
typename InContainer::value_type const &)> func) {
OutContainer out;
for (auto i = input.begin(); i != input.end(); ++i) {
out.push_back(func(*i));
}
return out;
}

template <typename ContainerType>
inline ContainerType filter(ContainerType const &c,
std::function<bool (typename ContainerType::value_type const &)> func) {
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libs/core/src/data/string.cpp
Expand Up @@ -609,9 +609,9 @@ void String::advanceFormat(String::const_iterator &i, String::const_iterator con
}
}

String String::join(QList<String> const &stringList, String const &sep)
String String::join(StringList const &stringList, String const &sep)
{
if (stringList.isEmpty()) return "";
if (stringList.isEmpty()) return {};

String joined;
QTextStream os(&joined);
Expand Down

0 comments on commit f11fdc2

Please sign in to comment.