如何将CMake列表视为集合并进行操作?

huangapple go评论77阅读模式
英文:

How do I manipulate CMake lists as sets?

问题

在CMake中,广泛使用列表。有时您有两个项目列表(基本上是字符串),想要考虑它们的交集、差异或并集。就像在这个情况中,这对我来说刚刚出现。

如何生成这样的交集、差异或并集列表?

注意:输出需要没有重复项,输入不需要。

英文:

In CMake, lists are used extensively. Sometimes you have two lists of items (strings, basically), and you want to consider their intersection, difference or union. Like in this case that just came up for me.

How do I produce such intersection, difference or union lists?

Note: The outputs need to have no duplicates, the inputs not really

答案1

得分: 6

假设我们的列表分别存储在变量 ST 中。

对于并集,请写入:

list(APPEND union_list ${S} ${T})
list(REMOVE_DUPLICATES union_list)

对于集合差异,请写入:

list(APPEND S_minus_T ${S})
list(REMOVE_ITEM S_minus_T ${T})

然后,我们使用一些集合恒等式通过对称差异来获取交集:

  • S∩T = (S∪T) ∖ (S∆T)
  • S∆T = (S∖T) ∪ (T\S)
英文:

Suppose our lists are in variables S and T.

For the union, write:

list(APPEND union_list ${S} ${T})
list(REMOVE_DUPLICATES union_list)

For set difference, write:

list(APPEND S_minus_T ${S})
list(REMOVE_ITEM S_minus_T ${T})

And then we use some set identities to obtain the intersection through the symmetric difference:

  • S∩T = (S∪T) ∖ (S∆T)
  • S∆T = (S∖T) ∪ (T\S)

huangapple
  • 本文由 发表于 2020年1月3日 19:58:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/59578248.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定