summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2023-04-26 13:27:46 (GMT)
committerMarc Chevrier <marc.chevrier@gmail.com>2023-04-29 07:54:22 (GMT)
commit87fe031a0703f07b8636f8ea59b6746788e71869 (patch)
treec5dd5704ef8688c65e9eae923299d5a00c76f3c9
parentf9da4cf8f1c56333511661de9fc74f4b82c1675b (diff)
downloadCMake-87fe031a0703f07b8636f8ea59b6746788e71869.zip
CMake-87fe031a0703f07b8636f8ea59b6746788e71869.tar.gz
CMake-87fe031a0703f07b8636f8ea59b6746788e71869.tar.bz2
cmList class: various enhancements
-rw-r--r--Source/CPack/IFW/cmCPackIFWCommon.cxx12
-rw-r--r--Source/cmGeneratorExpressionNode.cxx27
-rw-r--r--Source/cmList.cxx29
-rw-r--r--Source/cmList.h255
-rw-r--r--Source/cmListCommand.cxx4
-rw-r--r--Source/cmQtAutoGenInitializer.cxx4
-rw-r--r--Source/cmStringAlgorithms.h6
-rw-r--r--Tests/CMakeLib/testList.cxx69
8 files changed, 249 insertions, 157 deletions
diff --git a/Source/CPack/IFW/cmCPackIFWCommon.cxx b/Source/CPack/IFW/cmCPackIFWCommon.cxx
index 4ff3a10..4a868ae 100644
--- a/Source/CPack/IFW/cmCPackIFWCommon.cxx
+++ b/Source/CPack/IFW/cmCPackIFWCommon.cxx
@@ -80,15 +80,15 @@ void cmCPackIFWCommon::ExpandListArgument(
return;
}
- cmList::index_type i = 0;
- std::size_t c = args.size();
+ cmList::size_type i = 0;
+ auto c = args.size();
if (c % 2) {
argsOut[""] = args[i];
++i;
}
--c;
- for (; i < static_cast<cmList::index_type>(c); i += 2) {
+ for (; i < c; i += 2) {
argsOut[args[i]] = args[i + 1];
}
}
@@ -101,15 +101,15 @@ void cmCPackIFWCommon::ExpandListArgument(
return;
}
- cmList::index_type i = 0;
- std::size_t c = args.size();
+ cmList::size_type i = 0;
+ auto c = args.size();
if (c % 2) {
argsOut.insert(std::pair<std::string, std::string>("", args[i]));
++i;
}
--c;
- for (; i < static_cast<cmList::index_type>(c); i += 2) {
+ for (; i < c; i += 2) {
argsOut.insert(std::pair<std::string, std::string>(args[i], args[i + 1]));
}
}
diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx
index 9dcbc39..f774fdf 100644
--- a/Source/cmGeneratorExpressionNode.cxx
+++ b/Source/cmGeneratorExpressionNode.cxx
@@ -1157,12 +1157,17 @@ inline cmList GetList(std::string const& list)
return list.empty() ? cmList{} : cmList{ list, cmList::EmptyElements::Yes };
}
-bool GetNumericArgument(const std::string& arg, int& value)
+bool GetNumericArgument(const std::string& arg, cmList::index_type& value)
{
try {
std::size_t pos;
- value = std::stoi(arg, &pos);
+ if (sizeof(cmList::index_type) == sizeof(long)) {
+ value = std::stol(arg, &pos);
+ } else {
+ value = std::stoll(arg, &pos);
+ }
+
if (pos != arg.length()) {
// this is not a number
return false;
@@ -1176,7 +1181,7 @@ bool GetNumericArgument(const std::string& arg, int& value)
bool GetNumericArguments(
cmGeneratorExpressionContext* ctx, const GeneratorExpressionContent* cnt,
- Arguments const& args, std::vector<int>& indexes,
+ Arguments const& args, std::vector<cmList::index_type>& indexes,
cmList::ExpandElements expandElements = cmList::ExpandElements::No)
{
using IndexRange = cmRange<Arguments::const_iterator>;
@@ -1188,7 +1193,7 @@ bool GetNumericArguments(
}
for (auto const& value : arguments) {
- int index;
+ cmList::index_type index;
if (!GetNumericArgument(value, index)) {
reportError(ctx, cnt->GetOriginalExpression(),
cmStrCat("index: \"", value, "\" is not a valid index"));
@@ -1242,7 +1247,7 @@ static const struct ListNode : public cmGeneratorExpressionNode
return std::string{};
}
- std::vector<int> indexes;
+ std::vector<cmList::index_type> indexes;
if (!GetNumericArguments(ctx, cnt, args.advance(1), indexes,
cmList::ExpandElements::Yes)) {
return std::string{};
@@ -1273,7 +1278,7 @@ static const struct ListNode : public cmGeneratorExpressionNode
if (CheckListParameters(ctx, cnt, "SUBLIST"_s, args, 3)) {
auto list = GetList(args.front());
if (!list.empty()) {
- std::vector<int> indexes;
+ std::vector<cmList::index_type> indexes;
if (!GetNumericArguments(ctx, cnt, args.advance(1), indexes)) {
return std::string{};
}
@@ -1322,7 +1327,7 @@ static const struct ListNode : public cmGeneratorExpressionNode
false)) {
auto list = args.front();
args.advance(1);
- return cmList::append(args.begin(), args.end(), list);
+ return cmList::append(list, args.begin(), args.end());
}
return std::string{};
} },
@@ -1334,7 +1339,7 @@ static const struct ListNode : public cmGeneratorExpressionNode
false)) {
auto list = args.front();
args.advance(1);
- return cmList::prepend(args.begin(), args.end(), list);
+ return cmList::prepend(list, args.begin(), args.end());
}
return std::string{};
} },
@@ -1344,7 +1349,7 @@ static const struct ListNode : public cmGeneratorExpressionNode
Arguments& args) -> std::string {
if (CheckListParametersEx(ctx, cnt, "INSERT"_s, args.size(), 3,
false)) {
- int index;
+ cmList::index_type index;
if (!GetNumericArgument(args[1], index)) {
reportError(
ctx, cnt->GetOriginalExpression(),
@@ -1419,7 +1424,7 @@ static const struct ListNode : public cmGeneratorExpressionNode
if (CheckListParametersEx(ctx, cnt, "REMOVE_AT"_s, args.size(), 2,
false)) {
auto list = GetList(args.front());
- std::vector<int> indexes;
+ std::vector<cmList::index_type> indexes;
if (!GetNumericArguments(ctx, cnt, args.advance(1), indexes,
cmList::ExpandElements::Yes)) {
return std::string{};
@@ -1575,7 +1580,7 @@ static const struct ListNode : public cmGeneratorExpressionNode
while (!args.empty()) {
cmList indexList{ args.front() };
for (auto const& index : indexList) {
- int value;
+ cmList::index_type value;
if (!GetNumericArgument(index, value)) {
// this is not a number, stop processing
diff --git a/Source/cmList.cxx b/Source/cmList.cxx
index 2064afb..022fcd2 100644
--- a/Source/cmList.cxx
+++ b/Source/cmList.cxx
@@ -287,18 +287,20 @@ protected:
: TransformSelector(std::move(tag))
{
}
- TransformSelectorIndexes(std::string&& tag, std::vector<int> const& indexes)
+ TransformSelectorIndexes(std::string&& tag,
+ std::vector<index_type> const& indexes)
: TransformSelector(std::move(tag))
, Indexes(indexes)
{
}
- TransformSelectorIndexes(std::string&& tag, std::vector<int>&& indexes)
+ TransformSelectorIndexes(std::string&& tag,
+ std::vector<index_type>&& indexes)
: TransformSelector(std::move(tag))
, Indexes(indexes)
{
}
- int NormalizeIndex(index_type index, std::size_t count)
+ index_type NormalizeIndex(index_type index, std::size_t count)
{
if (index < 0) {
index = static_cast<index_type>(count) + index;
@@ -338,7 +340,7 @@ public:
class TransformSelectorFor : public TransformSelectorIndexes
{
public:
- TransformSelectorFor(int start, int stop, int step)
+ TransformSelectorFor(index_type start, index_type stop, index_type step)
: TransformSelectorIndexes("FOR")
, Start(start)
, Stop(stop)
@@ -369,7 +371,7 @@ public:
auto start = this->Start;
auto step = this->Step;
std::generate(this->Indexes.begin(), this->Indexes.end(),
- [&start, step]() -> int {
+ [&start, step]() -> index_type {
auto r = start;
start += step;
return r;
@@ -805,7 +807,7 @@ std::string cmList::join(cm::string_view glue) const
return cmJoin(this->Values, glue);
}
-std::string& cmList::append(cm::string_view value, std::string& list)
+std::string& cmList::append(std::string& list, cm::string_view value)
{
if (list.empty()) {
list = std::string(value);
@@ -816,7 +818,7 @@ std::string& cmList::append(cm::string_view value, std::string& list)
return list;
}
-std::string& cmList::prepend(cm::string_view value, std::string& list)
+std::string& cmList::prepend(std::string& list, cm::string_view value)
{
if (list.empty()) {
list = std::string(value);
@@ -884,7 +886,7 @@ cmList cmList::GetItems(std::vector<index_type>&& indexes) const
cmList listItems;
for (auto index : indexes) {
- listItems.emplace_back(this->at(index));
+ listItems.emplace_back(this->get_item(index));
}
return listItems;
@@ -898,9 +900,10 @@ cmList& cmList::RemoveItems(std::vector<index_type>&& indexes)
// compute all indexes
std::vector<size_type> idx(indexes.size());
- std::transform(
- indexes.cbegin(), indexes.cend(), idx.begin(),
- [this](const index_type& index) { return this->ComputeIndex(index); });
+ std::transform(indexes.cbegin(), indexes.cend(), idx.begin(),
+ [this](const index_type& index) -> size_type {
+ return this->ComputeIndex(index);
+ });
std::sort(idx.begin(), idx.end(),
[](size_type l, size_type r) { return l > r; });
@@ -927,8 +930,8 @@ cmList& cmList::RemoveItems(std::vector<std::string>&& items)
}
cmList::container_type::iterator cmList::Insert(
- container_type::const_iterator pos, std::string&& value,
- container_type& container, ExpandElements expandElements,
+ container_type& container, container_type::const_iterator pos,
+ std::string&& value, ExpandElements expandElements,
EmptyElements emptyElements)
{
auto delta = std::distance(container.cbegin(), pos);
diff --git a/Source/cmList.h b/Source/cmList.h
index 8a1cb8e..26bf42e 100644
--- a/Source/cmList.h
+++ b/Source/cmList.h
@@ -6,6 +6,7 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <algorithm>
+#include <cstdint>
#include <initializer_list>
#include <iterator>
#include <memory>
@@ -29,8 +30,10 @@
* expanded. The expansion can be controlled by the cmList::ExpandElements
* option.
*
- * There is an exception to this rule. The following methods do not expand
- * their argument: cmList::push_back, cmList::emplace and cmList::emplace_back.
+ * There ate some exceptions to this rule:
+ * * When the input argument is a cmList instance, the value is not expanded.
+ * * The following methods do not expand their argument: cmList::push_back,
+ * cmList::emplace and cmList::emplace_back.
*/
class cmList
@@ -40,7 +43,7 @@ public:
using value_type = container_type::value_type;
using allocator_type = container_type::allocator_type;
- using index_type = int;
+ using index_type = std::intptr_t;
using size_type = container_type::size_type;
using difference_type = container_type::difference_type;
using reference = container_type::reference;
@@ -76,8 +79,18 @@ public:
this->assign(value, expandElements, emptyElements);
}
cmList(cm::string_view value, EmptyElements emptyElements)
+ : cmList(value, ExpandElements::Yes, emptyElements)
+ {
+ }
+ cmList(std::string const& value,
+ ExpandElements expandElements = ExpandElements::Yes,
+ EmptyElements emptyElements = EmptyElements::No)
+ {
+ this->assign(value, expandElements, emptyElements);
+ }
+ cmList(std::string const& value, EmptyElements emptyElements)
+ : cmList(value, ExpandElements::Yes, emptyElements)
{
- this->assign(value, ExpandElements::Yes, emptyElements);
}
cmList(cmValue list, ExpandElements expandElements = ExpandElements::Yes,
EmptyElements emptyElements = EmptyElements::No)
@@ -137,6 +150,11 @@ public:
this->assign(value);
return *this;
}
+ cmList& operator=(std::string const& value)
+ {
+ this->assign(value);
+ return *this;
+ }
cmList& operator=(cmValue value)
{
if (value) {
@@ -177,6 +195,17 @@ public:
{
this->assign(value, ExpandElements::Yes, emptyElements);
}
+ void assign(std::string const& value,
+ ExpandElements expandElements = ExpandElements::Yes,
+ EmptyElements emptyElements = EmptyElements::No)
+ {
+ this->clear();
+ this->append(value, expandElements, emptyElements);
+ }
+ void assign(std::string const& value, EmptyElements emptyElements)
+ {
+ this->assign(value, ExpandElements::Yes, emptyElements);
+ }
void assign(cmValue value,
ExpandElements expandElements = ExpandElements::Yes,
EmptyElements emptyElements = EmptyElements::No)
@@ -206,17 +235,17 @@ public:
this->assign(first, last, ExpandElements::Yes, emptyElements);
}
void assign(const cmList& init,
- ExpandElements expandElements = ExpandElements::Yes,
+ ExpandElements expandElements = ExpandElements::No,
EmptyElements emptyElements = EmptyElements::No)
{
this->assign(init.begin(), init.end(), expandElements, emptyElements);
}
void assign(const cmList& init, EmptyElements emptyElements)
{
- this->assign(init, ExpandElements::Yes, emptyElements);
+ this->assign(init, ExpandElements::No, emptyElements);
}
void assign(cmList&& init,
- ExpandElements expandElements = ExpandElements::Yes,
+ ExpandElements expandElements = ExpandElements::No,
EmptyElements emptyElements = EmptyElements::No)
{
this->assign(std::make_move_iterator(init.begin()),
@@ -226,7 +255,7 @@ public:
}
void assign(cmList&& init, EmptyElements emptyElements)
{
- this->assign(std::move(init), ExpandElements::Yes, emptyElements);
+ this->assign(std::move(init), ExpandElements::No, emptyElements);
}
void assign(const container_type& init,
ExpandElements expandElements = ExpandElements::Yes,
@@ -267,24 +296,21 @@ public:
operator container_type&&() && noexcept { return std::move(this->Values); }
// Element access
- reference at(index_type pos)
+ reference at(size_type pos) { return this->Values.at(pos); }
+ const_reference at(size_type pos) const { return this->Values.at(pos); }
+
+ reference operator[](size_type pos) { return this->Values[pos]; }
+ const_reference operator[](size_type pos) const { return this->Values[pos]; }
+
+ reference get_item(index_type pos)
{
return this->Values.at(this->ComputeIndex(pos));
}
- const_reference at(index_type pos) const
+ const_reference get_item(index_type pos) const
{
return this->Values.at(this->ComputeIndex(pos));
}
- reference operator[](index_type pos)
- {
- return this->Values[this->ComputeIndex(pos, false)];
- }
- const_reference operator[](index_type pos) const
- {
- return this->Values[this->ComputeIndex(pos, false)];
- }
-
reference front() { return this->Values.front(); }
const_reference front() const { return this->Values.front(); }
@@ -363,7 +389,7 @@ public:
ExpandElements expandElements = ExpandElements::Yes,
EmptyElements emptyElements = EmptyElements::No)
{
- return cmList::Insert(pos, std::string(value), this->Values,
+ return cmList::Insert(this->Values, pos, std::string(value),
expandElements, emptyElements);
}
iterator insert(const_iterator pos, cm::string_view value,
@@ -371,6 +397,18 @@ public:
{
return this->insert(pos, value, ExpandElements::Yes, emptyElements);
}
+ iterator insert(const_iterator pos, std::string const& value,
+ ExpandElements expandElements = ExpandElements::Yes,
+ EmptyElements emptyElements = EmptyElements::No)
+ {
+ return cmList::Insert(this->Values, pos, value, expandElements,
+ emptyElements);
+ }
+ iterator insert(const_iterator pos, std::string const& value,
+ EmptyElements emptyElements)
+ {
+ return this->insert(pos, value, ExpandElements::Yes, emptyElements);
+ }
iterator insert(const_iterator pos, cmValue value,
ExpandElements expandElements = ExpandElements::Yes,
EmptyElements emptyElements = EmptyElements::No)
@@ -392,7 +430,7 @@ public:
ExpandElements expandElements = ExpandElements::Yes,
EmptyElements emptyElements = EmptyElements::No)
{
- return cmList::Insert(pos, first, last, this->Values, expandElements,
+ return cmList::Insert(this->Values, pos, first, last, expandElements,
emptyElements);
}
template <typename InputIterator>
@@ -402,7 +440,7 @@ public:
return this->insert(pos, first, last, ExpandElements::Yes, emptyElements);
}
iterator insert(const_iterator pos, const cmList& values,
- ExpandElements expandElements = ExpandElements::Yes,
+ ExpandElements expandElements = ExpandElements::No,
EmptyElements emptyElements = EmptyElements::No)
{
return this->insert(pos, values.begin(), values.end(), expandElements,
@@ -411,10 +449,10 @@ public:
iterator insert(const_iterator pos, const cmList& values,
EmptyElements emptyElements)
{
- return this->insert(pos, values, ExpandElements::Yes, emptyElements);
+ return this->insert(pos, values, ExpandElements::No, emptyElements);
}
iterator insert(const_iterator pos, cmList&& values,
- ExpandElements expandElements = ExpandElements::Yes,
+ ExpandElements expandElements = ExpandElements::No,
EmptyElements emptyElements = EmptyElements::No)
{
auto result = this->insert(pos, std::make_move_iterator(values.begin()),
@@ -427,7 +465,7 @@ public:
iterator insert(const_iterator pos, cmList&& values,
EmptyElements emptyElements)
{
- return this->insert(pos, std::move(values), ExpandElements::Yes,
+ return this->insert(pos, std::move(values), ExpandElements::No,
emptyElements);
}
iterator insert(const_iterator pos, const container_type& values,
@@ -474,6 +512,16 @@ public:
{
return this->append(value, ExpandElements::Yes, emptyElements);
}
+ iterator append(std::string const& value,
+ ExpandElements expandElements = ExpandElements::Yes,
+ EmptyElements emptyElements = EmptyElements::No)
+ {
+ return this->insert(this->cend(), value, expandElements, emptyElements);
+ }
+ iterator append(std::string const& value, EmptyElements emptyElements)
+ {
+ return this->append(value, ExpandElements::Yes, emptyElements);
+ }
iterator append(cmValue value,
ExpandElements expandElements = ExpandElements::Yes,
EmptyElements emptyElements = EmptyElements::No)
@@ -503,7 +551,7 @@ public:
return this->append(first, last, ExpandElements::Yes, emptyElements);
}
iterator append(const cmList& values,
- ExpandElements expandElements = ExpandElements::Yes,
+ ExpandElements expandElements = ExpandElements::No,
EmptyElements emptyElements = EmptyElements::No)
{
return this->append(values.begin(), values.end(), expandElements,
@@ -511,10 +559,10 @@ public:
}
iterator append(const cmList& values, EmptyElements emptyElements)
{
- return this->append(values, ExpandElements::Yes, emptyElements);
+ return this->append(values, ExpandElements::No, emptyElements);
}
iterator append(cmList&& values,
- ExpandElements expandElements = ExpandElements::Yes,
+ ExpandElements expandElements = ExpandElements::No,
EmptyElements emptyElements = EmptyElements::No)
{
auto result = this->append(std::make_move_iterator(values.begin()),
@@ -526,7 +574,7 @@ public:
}
iterator append(cmList&& values, EmptyElements emptyElements)
{
- return this->append(std::move(values), ExpandElements::Yes, emptyElements);
+ return this->append(std::move(values), ExpandElements::No, emptyElements);
}
iterator append(const container_type& values,
ExpandElements expandElements = ExpandElements::Yes,
@@ -569,6 +617,16 @@ public:
{
return this->prepend(value, ExpandElements::Yes, emptyElements);
}
+ iterator prepend(std::string const& value,
+ ExpandElements expandElements = ExpandElements::Yes,
+ EmptyElements emptyElements = EmptyElements::No)
+ {
+ return this->insert(this->cbegin(), value, expandElements, emptyElements);
+ }
+ iterator prepend(std::string const& value, EmptyElements emptyElements)
+ {
+ return this->prepend(value, ExpandElements::Yes, emptyElements);
+ }
iterator prepend(cmValue value,
ExpandElements expandElements = ExpandElements::Yes,
EmptyElements emptyElements = EmptyElements::No)
@@ -598,7 +656,7 @@ public:
return this->prepend(first, last, ExpandElements::Yes, emptyElements);
}
iterator prepend(const cmList& values,
- ExpandElements expandElements = ExpandElements::Yes,
+ ExpandElements expandElements = ExpandElements::No,
EmptyElements emptyElements = EmptyElements::No)
{
return this->prepend(values.begin(), values.end(), expandElements,
@@ -606,10 +664,10 @@ public:
}
iterator prepend(const cmList& values, EmptyElements emptyElements)
{
- return this->prepend(values, ExpandElements::Yes, emptyElements);
+ return this->prepend(values, ExpandElements::No, emptyElements);
}
iterator prepend(cmList&& values,
- ExpandElements expandElements = ExpandElements::Yes,
+ ExpandElements expandElements = ExpandElements::No,
EmptyElements emptyElements = EmptyElements::No)
{
auto result = this->prepend(std::make_move_iterator(values.begin()),
@@ -621,8 +679,7 @@ public:
}
iterator prepend(cmList&& values, EmptyElements emptyElements)
{
- return this->prepend(std::move(values), ExpandElements::Yes,
- emptyElements);
+ return this->prepend(std::move(values), ExpandElements::No, emptyElements);
}
iterator prepend(const container_type& values,
ExpandElements expandElements = ExpandElements::Yes,
@@ -656,6 +713,7 @@ public:
return this->insert(this->cbegin(), ilist);
}
+ void push_back(std::string const& value) { this->Values.push_back(value); }
void push_back(cm::string_view value)
{
this->Values.push_back(std::string{ value });
@@ -735,6 +793,8 @@ public:
cmList& remove_duplicates();
+ void resize(size_type count) { this->Values.resize(count); }
+
enum class FilterMode
{
INCLUDE,
@@ -882,46 +942,61 @@ public:
// ==============
// these methods can be used to store CMake list expansion directly in a
// std::vector.
- static void assign(cm::string_view value,
- std::vector<std::string>& container,
+ static void assign(std::vector<std::string>& container,
+ cm::string_view value,
+ EmptyElements emptyElements = EmptyElements::No)
+ {
+ container.clear();
+ cmList::append(container, value, emptyElements);
+ }
+ static void assign(std::vector<std::string>& container,
+ std::string const& value,
EmptyElements emptyElements = EmptyElements::No)
{
container.clear();
- cmList::append(value, container, emptyElements);
+ cmList::append(container, value, emptyElements);
}
- static void assign(cmValue value, std::vector<std::string>& container,
+ static void assign(std::vector<std::string>& container, cmValue value,
EmptyElements emptyElements = EmptyElements::No)
{
if (value) {
- cmList::assign(*value, container, emptyElements);
+ cmList::assign(container, *value, emptyElements);
} else {
container.clear();
}
}
template <typename InputIterator>
- static void assign(InputIterator first, InputIterator last,
- std::vector<std::string>& container,
+ static void assign(std::vector<std::string>& container, InputIterator first,
+ InputIterator last,
EmptyElements emptyElements = EmptyElements::No)
{
container.clear();
- cmList::append(first, last, container, emptyElements);
+ cmList::append(container, first, last, emptyElements);
}
static std::vector<std::string>::iterator insert(
- std::vector<std::string>::const_iterator pos, cm::string_view value,
std::vector<std::string>& container,
+ std::vector<std::string>::const_iterator pos, cm::string_view value,
EmptyElements emptyElements = EmptyElements::No)
{
- return cmList::Insert(pos, std::string(value), container,
+ return cmList::Insert(container, pos, std::string(value),
ExpandElements::Yes, emptyElements);
}
static std::vector<std::string>::iterator insert(
- std::vector<std::string>::const_iterator pos, cmValue value,
std::vector<std::string>& container,
+ std::vector<std::string>::const_iterator pos, std::string const& value,
+ EmptyElements emptyElements = EmptyElements::No)
+ {
+ return cmList::Insert(container, pos, value, ExpandElements::Yes,
+ emptyElements);
+ }
+ static std::vector<std::string>::iterator insert(
+ std::vector<std::string>& container,
+ std::vector<std::string>::const_iterator pos, cmValue value,
EmptyElements emptyElements = EmptyElements::No)
{
if (value) {
- return cmList::insert(pos, *value, container, emptyElements);
+ return cmList::insert(container, pos, *value, emptyElements);
}
auto delta = std::distance(container.cbegin(), pos);
@@ -929,63 +1004,73 @@ public:
}
template <typename InputIterator>
static std::vector<std::string>::iterator insert(
+ std::vector<std::string>& container,
std::vector<std::string>::const_iterator pos, InputIterator first,
- InputIterator last, std::vector<std::string>& container,
- EmptyElements emptyElements = EmptyElements::No)
+ InputIterator last, EmptyElements emptyElements = EmptyElements::No)
{
- return cmList::Insert(pos, first, last, container, ExpandElements::Yes,
+ return cmList::Insert(container, pos, first, last, ExpandElements::Yes,
emptyElements);
}
static std::vector<std::string>::iterator append(
- cm::string_view value, std::vector<std::string>& container,
+ std::vector<std::string>& container, cm::string_view value,
EmptyElements emptyElements = EmptyElements::No)
{
- return cmList::insert(container.cend(), value, container, emptyElements);
+ return cmList::insert(container, container.cend(), value, emptyElements);
}
static std::vector<std::string>::iterator append(
- cmValue value, std::vector<std::string>& container,
+ std::vector<std::string>& container, std::string const& value,
+ EmptyElements emptyElements = EmptyElements::No)
+ {
+ return cmList::insert(container, container.cend(), value, emptyElements);
+ }
+ static std::vector<std::string>::iterator append(
+ std::vector<std::string>& container, cmValue value,
EmptyElements emptyElements = EmptyElements::No)
{
if (value) {
- return cmList::append(*value, container, emptyElements);
+ return cmList::append(container, *value, emptyElements);
}
return container.end();
}
template <typename InputIterator>
static std::vector<std::string>::iterator append(
- InputIterator first, InputIterator last,
- std::vector<std::string>& container,
- EmptyElements emptyElements = EmptyElements::No)
+ std::vector<std::string>& container, InputIterator first,
+ InputIterator last, EmptyElements emptyElements = EmptyElements::No)
{
- return cmList::insert(container.cend(), first, last, container,
+ return cmList::insert(container, container.cend(), first, last,
emptyElements);
}
static std::vector<std::string>::iterator prepend(
- cm::string_view value, std::vector<std::string>& container,
+ std::vector<std::string>& container, cm::string_view value,
EmptyElements emptyElements = EmptyElements::No)
{
- return cmList::insert(container.cbegin(), value, container, emptyElements);
+ return cmList::insert(container, container.cbegin(), value, emptyElements);
}
static std::vector<std::string>::iterator prepend(
- cmValue value, std::vector<std::string>& container,
+ std::vector<std::string>& container, std::string const& value,
+ EmptyElements emptyElements = EmptyElements::No)
+ {
+ return cmList::insert(container, container.cbegin(), value, emptyElements);
+ }
+ static std::vector<std::string>::iterator prepend(
+ std::vector<std::string>& container, cmValue value,
EmptyElements emptyElements = EmptyElements::No)
{
if (value) {
- return cmList::prepend(*value, container, emptyElements);
+ return cmList::prepend(container, *value, emptyElements);
}
return container.begin();
}
template <typename InputIterator>
static std::vector<std::string>::iterator prepend(
- InputIterator first, InputIterator last,
- std::vector<std::string>& container,
- EmptyElements emptyElements = EmptyElements::No)
+ std::vector<std::string>& container, InputIterator first,
+ InputIterator last, EmptyElements emptyElements = EmptyElements::No)
{
- return cmList::insert(container.cbegin(), first, last, container,
+ return cmList::insert(container, container.cbegin(), first, last,
emptyElements);
}
@@ -993,40 +1078,40 @@ public:
// but without any intermediate expansion. So the operation is simply a
// string concatenation with special handling for the CMake list item
// separator
- static std::string& append(cm::string_view value, std::string& list);
+ static std::string& append(std::string& list, cm::string_view value);
template <typename InputIterator>
- static std::string& append(InputIterator first, InputIterator last,
- std::string& list)
+ static std::string& append(std::string& list, InputIterator first,
+ InputIterator last)
{
if (first == last) {
return list;
}
- return cmList::append(cm::string_view{ std::accumulate(
+ 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) +
std::string(cmList::element_separator) + b;
- }) },
- list);
+ }) });
}
- static std::string& prepend(cm::string_view value, std::string& list);
+ static std::string& prepend(std::string& list, cm::string_view value);
template <typename InputIterator>
- static std::string& prepend(InputIterator first, InputIterator last,
- std::string& list)
+ static std::string& prepend(std::string& list, InputIterator first,
+ InputIterator last)
{
if (first == last) {
return list;
}
- return cmList::prepend(cm::string_view{ std::accumulate(
+ return cmList::prepend(list,
+ cm::string_view{ std::accumulate(
std::next(first), last, *first,
[](std::string a, const std::string& b) {
return std::move(a) +
std::string(cmList::element_separator) + b;
- }) },
- list);
+ }) });
}
// Non-members
@@ -1049,26 +1134,26 @@ private:
cmList& RemoveItems(std::vector<index_type>&& indexes);
cmList& RemoveItems(std::vector<std::string>&& items);
- static container_type::iterator Insert(container_type::const_iterator pos,
+ static container_type::iterator Insert(container_type& container,
+ container_type::const_iterator pos,
std::string&& value,
- container_type& container,
ExpandElements expandElements,
EmptyElements emptyElements);
- static container_type::iterator Insert(container_type::const_iterator pos,
+ static container_type::iterator Insert(container_type& container,
+ container_type::const_iterator pos,
const std::string& value,
- container_type& container,
ExpandElements expandElements,
EmptyElements emptyElements)
{
auto tmp = value;
- return cmList::Insert(pos, std::move(tmp), container, expandElements,
+ return cmList::Insert(container, pos, std::move(tmp), expandElements,
emptyElements);
}
template <typename InputIterator>
- static container_type::iterator Insert(container_type::const_iterator pos,
+ static container_type::iterator Insert(container_type& container,
+ container_type::const_iterator pos,
InputIterator first,
InputIterator last,
- container_type& container,
ExpandElements expandElements,
EmptyElements emptyElements)
{
@@ -1082,7 +1167,7 @@ private:
if (expandElements == ExpandElements::Yes) {
for (; first != last; ++first) {
auto size = container.size();
- insertPos = cmList::Insert(insertPos, *first, container,
+ insertPos = cmList::Insert(container, insertPos, *first,
expandElements, emptyElements);
insertPos += container.size() - size;
}
diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx
index 40be0ce..acffa2e 100644
--- a/Source/cmListCommand.cxx
+++ b/Source/cmListCommand.cxx
@@ -205,7 +205,7 @@ bool HandleAppendCommand(std::vector<std::string> const& args,
GetListString(listString, listName, makefile);
makefile.AddDefinition(
- listName, cmList::append(args.begin() + 2, args.end(), listString));
+ listName, cmList::append(listString, args.begin() + 2, args.end()));
return true;
}
@@ -226,7 +226,7 @@ bool HandlePrependCommand(std::vector<std::string> const& args,
GetListString(listString, listName, makefile);
makefile.AddDefinition(
- listName, cmList::prepend(args.begin() + 2, args.end(), listString));
+ listName, cmList::prepend(listString, args.begin() + 2, args.end()));
return true;
}
diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx
index 4c45949..9f00a52 100644
--- a/Source/cmQtAutoGenInitializer.cxx
+++ b/Source/cmQtAutoGenInitializer.cxx
@@ -559,9 +559,7 @@ bool cmQtAutoGenInitializer::InitCustomTargets()
"Q_PLUGIN_METADATA",
"[\n][ \t]*Q_PLUGIN_METADATA[ \t]*\\("
"[^\\)]*FILE[ \t]*\"([^\"]+)\"");
- for (cmList::index_type ii = 0;
- ii != static_cast<cmList::index_type>(filterList.size());
- ii += 2) {
+ for (cmList::size_type ii = 0; ii != filterList.size(); ii += 2) {
this->Moc.DependFilters.emplace_back(filterList[ii],
filterList[ii + 1]);
}
diff --git a/Source/cmStringAlgorithms.h b/Source/cmStringAlgorithms.h
index 4ccbb8e..0e9dfbf 100644
--- a/Source/cmStringAlgorithms.h
+++ b/Source/cmStringAlgorithms.h
@@ -97,14 +97,14 @@ inline void cmExpandList(cm::string_view arg,
std::vector<std::string>& argsOut,
bool emptyArgs = false)
{
- cmList::append(arg, argsOut,
+ cmList::append(argsOut, arg,
emptyArgs ? cmList::EmptyElements::Yes
: cmList::EmptyElements::No);
}
inline void cmExpandList(cmValue arg, std::vector<std::string>& argsOut,
bool emptyArgs = false)
{
- cmList::append(arg, argsOut,
+ cmList::append(argsOut, arg,
emptyArgs ? cmList::EmptyElements::Yes
: cmList::EmptyElements::No);
}
@@ -118,7 +118,7 @@ template <class InputIt>
void cmExpandLists(InputIt first, InputIt last,
std::vector<std::string>& argsOut)
{
- cmList::append(first, last, argsOut);
+ cmList::append(argsOut, first, last);
}
/** Concatenate string pieces into a single string. */
diff --git a/Tests/CMakeLib/testList.cxx b/Tests/CMakeLib/testList.cxx
index 7294be0..ff1f278 100644
--- a/Tests/CMakeLib/testList.cxx
+++ b/Tests/CMakeLib/testList.cxx
@@ -9,6 +9,7 @@
#include <vector>
#include <cm/string_view>
+#include <cmext/string_view>
#include "cmList.h"
@@ -42,7 +43,7 @@ bool testConstructors()
}
{
cmList list1{ "aa", "bb" };
- cmList list2("aa;bb");
+ cmList list2("aa;bb"_s);
if (list1.size() != 2 || list2.size() != 2 || list1 != list2) {
result = false;
@@ -174,7 +175,7 @@ bool testAssign()
{
cmList list{ "cc", "dd" };
- list = "aa;bb";
+ list = "aa;bb"_s;
if (list.size() != 2) {
result = false;
}
@@ -195,7 +196,7 @@ bool testConversions()
bool result = true;
{
- cmList list("a;b;c");
+ cmList list("a;b;c"_s);
std::string s = list.to_string();
if (s != "a;b;c") {
@@ -203,7 +204,7 @@ bool testConversions()
}
}
{
- cmList list("a;b;c");
+ cmList list("a;b;c"_s);
std::vector<std::string> v = list;
if (list.size() != 3 || v.size() != 3) {
@@ -211,7 +212,7 @@ bool testConversions()
}
}
{
- cmList list("a;b;c");
+ cmList list("a;b;c"_s);
std::vector<std::string> v = std::move(list);
// Microsoft compiler is not able to handle correctly the move semantics
@@ -221,7 +222,7 @@ bool testConversions()
}
}
{
- cmList list("a;b;c");
+ cmList list("a;b;c"_s);
std::vector<std::string> v;
// compiler is not able to select the cmList conversion operator
@@ -247,20 +248,20 @@ bool testAccess()
{
cmList list{ "a", "b", "c" };
- if (list.at(1) != "b") {
+ if (list.get_item(1) != "b") {
result = false;
}
}
{
cmList list{ "a", "b", "c" };
- if (list.at(-3) != "a") {
+ if (list.get_item(-3) != "a") {
result = false;
}
}
{
try {
cmList list{ "a", "b", "c" };
- if (list.at(4) != "a") {
+ if (list.get_item(4) != "a") {
result = false;
}
} catch (std::out_of_range&) {
@@ -269,7 +270,7 @@ bool testAccess()
{
try {
cmList list{ "a", "b", "c" };
- if (list.at(-4) != "a") {
+ if (list.get_item(-4) != "a") {
result = false;
}
} catch (std::out_of_range&) {
@@ -342,7 +343,7 @@ bool testModifiers()
{
cmList list{ "1;2;3;4;5" };
- auto it = list.insert(list.begin() + 2, "6;7;8");
+ auto it = list.insert(list.begin() + 2, "6;7;8"_s);
if (list.size() != 8 || list.to_string() != "1;2;6;7;8;3;4;5") {
result = false;
}
@@ -354,7 +355,7 @@ bool testModifiers()
cmList list{ "1;2;3;4;5" };
auto it =
- list.insert(list.begin() + 2, "6;7;8", cmList::ExpandElements::No);
+ list.insert(list.begin() + 2, "6;7;8"_s, cmList::ExpandElements::No);
if (list.size() != 6 || list.to_string() != "1;2;6;7;8;3;4;5") {
result = false;
}
@@ -479,7 +480,7 @@ bool testRemoveItems()
bool result = true;
{
- cmList list("a;b;c;d;e;f;g;h");
+ cmList list("a;b;c;d;e;f;g;h"_s);
list.remove_items({ 1, 3, 5 });
@@ -488,7 +489,7 @@ bool testRemoveItems()
}
}
{
- cmList list("a;b;c;b;a;d;e;f");
+ cmList list("a;b;c;b;a;d;e;f"_s);
list.remove_items({ "a", "b", "h" });
@@ -497,7 +498,7 @@ bool testRemoveItems()
}
}
{
- cmList list("a;b;c;d;e;f;g;h");
+ cmList list("a;b;c;d;e;f;g;h"_s);
std::vector<cmList::index_type> remove{ 1, 3, 5 };
list.remove_items(remove.begin(), remove.end());
@@ -507,7 +508,7 @@ bool testRemoveItems()
}
}
{
- cmList list("a;b;c;b;a;d;e;f");
+ cmList list("a;b;c;b;a;d;e;f"_s);
std::vector<std::string> remove{ "b", "a", "h" };
list.remove_items(remove.begin(), remove.end());
@@ -529,7 +530,7 @@ bool testRemoveDuplicates()
bool result = true;
{
- cmList list("b;c;b;a;a;c;b;a;c;b");
+ cmList list("b;c;b;a;a;c;b;a;c;b"_s);
list.remove_duplicates();
@@ -803,7 +804,7 @@ bool testStaticModifiers()
{
std::vector<std::string> v{ "a", "b", "c" };
- cmList::assign("d;e", v);
+ cmList::assign(v, "d;e"_s);
if (v.size() != 2 || v[0] != "d" || v[1] != "e") {
result = false;
@@ -811,7 +812,7 @@ bool testStaticModifiers()
}
{
std::vector<std::string> v{ "a", "b", "c" };
- cmList::append("d;;e", v);
+ cmList::append(v, "d;;e"_s);
if (v.size() != 5 || v[3] != "d" || v[4] != "e") {
result = false;
@@ -819,7 +820,7 @@ bool testStaticModifiers()
}
{
std::vector<std::string> v{ "a", "b", "c" };
- cmList::append("d;;e", v, cmList::EmptyElements::Yes);
+ cmList::append(v, "d;;e"_s, cmList::EmptyElements::Yes);
if (v.size() != 6 || v[3] != "d" || !v[4].empty() || v[5] != "e") {
result = false;
@@ -827,7 +828,7 @@ bool testStaticModifiers()
}
{
std::vector<std::string> v{ "a", "b", "c" };
- cmList::prepend("d;e", v);
+ cmList::prepend(v, "d;e"_s);
if (v.size() != 5 || v[0] != "d" || v[1] != "e") {
result = false;
@@ -835,7 +836,7 @@ bool testStaticModifiers()
}
{
std::vector<std::string> v{ "a", "b", "c" };
- cmList::prepend("d;;e", v, cmList::EmptyElements::Yes);
+ cmList::prepend(v, "d;;e"_s, cmList::EmptyElements::Yes);
if (v.size() != 6 || v[0] != "d" || !v[1].empty() || v[2] != "e") {
result = false;
@@ -843,7 +844,7 @@ bool testStaticModifiers()
}
{
std::string list{ "a;b;c" };
- cmList::append("d;e", list);
+ cmList::append(list, "d;e"_s);
if (list != "a;b;c;d;e") {
result = false;
@@ -851,7 +852,7 @@ bool testStaticModifiers()
}
{
std::string list;
- cmList::append("d;e", list);
+ cmList::append(list, "d;e"_s);
if (list != "d;e") {
result = false;
@@ -859,7 +860,7 @@ bool testStaticModifiers()
}
{
std::string list{ "a;b;c" };
- cmList::append("", list);
+ cmList::append(list, "");
if (list != "a;b;c;") {
result = false;
@@ -868,7 +869,7 @@ bool testStaticModifiers()
{
std::string list{ "a;b;c" };
std::vector<std::string> v{ "d", "e" };
- cmList::append(v.begin(), v.end(), list);
+ cmList::append(list, v.begin(), v.end());
if (list != "a;b;c;d;e") {
result = false;
@@ -877,7 +878,7 @@ bool testStaticModifiers()
{
std::string list{ "a;b;c" };
std::vector<std::string> v;
- cmList::append(v.begin(), v.end(), list);
+ cmList::append(list, v.begin(), v.end());
if (list != "a;b;c") {
result = false;
@@ -886,7 +887,7 @@ bool testStaticModifiers()
{
std::string list;
std::vector<std::string> v{ "d", "e" };
- cmList::append(v.begin(), v.end(), list);
+ cmList::append(list, v.begin(), v.end());
if (list != "d;e") {
result = false;
@@ -894,7 +895,7 @@ bool testStaticModifiers()
}
{
std::string list{ "a;b;c" };
- cmList::prepend("d;e", list);
+ cmList::prepend(list, "d;e");
if (list != "d;e;a;b;c") {
result = false;
@@ -902,7 +903,7 @@ bool testStaticModifiers()
}
{
std::string list;
- cmList::prepend("d;e", list);
+ cmList::prepend(list, "d;e");
if (list != "d;e") {
result = false;
@@ -910,7 +911,7 @@ bool testStaticModifiers()
}
{
std::string list{ "a;b;c" };
- cmList::prepend("", list);
+ cmList::prepend(list, "");
if (list != ";a;b;c") {
result = false;
@@ -919,7 +920,7 @@ bool testStaticModifiers()
{
std::string list{ "a;b;c" };
std::vector<std::string> v{ "d", "e" };
- cmList::prepend(v.begin(), v.end(), list);
+ cmList::prepend(list, v.begin(), v.end());
if (list != "d;e;a;b;c") {
result = false;
@@ -928,7 +929,7 @@ bool testStaticModifiers()
{
std::string list{ "a;b;c" };
std::vector<std::string> v;
- cmList::prepend(v.begin(), v.end(), list);
+ cmList::prepend(list, v.begin(), v.end());
if (list != "a;b;c") {
result = false;
@@ -937,7 +938,7 @@ bool testStaticModifiers()
{
std::string list;
std::vector<std::string> v{ "d", "e" };
- cmList::prepend(v.begin(), v.end(), list);
+ cmList::prepend(list, v.begin(), v.end());
if (list != "d;e") {
result = false;