summaryrefslogtreecommitdiffstats
path: root/Source/cmList.h
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2023-06-20 14:32:27 (GMT)
committerMarc Chevrier <marc.chevrier@gmail.com>2023-06-22 13:44:17 (GMT)
commit45f17e5a8566fcdec0071a5ed1bc2656968bf258 (patch)
treed7391fbaa4ab69666ced6dd940892c5c401bcfca /Source/cmList.h
parent88e7ad0084bd6a2fa6f032d7be1ee5d993440dcf (diff)
downloadCMake-45f17e5a8566fcdec0071a5ed1bc2656968bf258.zip
CMake-45f17e5a8566fcdec0071a5ed1bc2656968bf258.tar.gz
CMake-45f17e5a8566fcdec0071a5ed1bc2656968bf258.tar.bz2
cmList: Add container conversion to string
Diffstat (limited to 'Source/cmList.h')
-rw-r--r--Source/cmList.h41
1 files changed, 38 insertions, 3 deletions
diff --git a/Source/cmList.h b/Source/cmList.h
index eba0400..9ee4a46 100644
--- a/Source/cmList.h
+++ b/Source/cmList.h
@@ -22,6 +22,9 @@
#include "cmValue.h"
+template <typename T>
+class BT;
+
/**
* CMake lists management
* A CMake list is a string where list elements are separated by the ';'
@@ -936,7 +939,10 @@ public:
std::vector<std::string> const& args,
std::unique_ptr<TransformSelector> = {});
- std::string join(cm::string_view glue) const;
+ std::string join(cm::string_view glue) const
+ {
+ return cmList::Join(this->Values, glue);
+ }
void swap(cmList& other) noexcept { this->Values.swap(other.Values); }
@@ -1092,8 +1098,8 @@ public:
return cmList::append(list,
cm::string_view{ std::accumulate(
std::next(first), last, *first,
- [](std::string a, const std::string& b) {
- return std::move(a) +
+ [](const std::string& a, const std::string& b) {
+ return a +
std::string(cmList::element_separator) + b;
}) });
}
@@ -1116,6 +1122,13 @@ public:
}) });
}
+ template <typename Range,
+ cm::enable_if_t<cm::is_range<Range>::value, int> = 0>
+ static std::string to_string(Range const& r)
+ {
+ return cmList::Join(r, cmList::element_separator);
+ }
+
// Non-members
// ===========
friend inline bool operator==(const cmList& lhs, const cmList& rhs) noexcept
@@ -1185,6 +1198,28 @@ private:
return container.begin() + delta;
}
+ static std::string const& ToString(std::string const& s) { return s; }
+ static std::string ToString(cm::string_view s) { return std::string{ s }; }
+ static std::string const& ToString(BT<std::string> const&);
+
+ template <typename Range>
+ static std::string Join(Range const& r, cm::string_view glue)
+ {
+ if (cm::size(r) == 0) {
+ return std::string{};
+ }
+
+ const auto sep = std::string{ glue };
+
+ return std::accumulate(
+ std::next(std::begin(r)), std::end(r), cmList::ToString(*std::begin(r)),
+ [&sep](std::string const& a,
+ typename std::iterator_traits<decltype(std::begin(
+ r))>::value_type const& b) -> std::string {
+ return a + sep + cmList::ToString(b);
+ });
+ }
+
container_type Values;
};