Skip to content

Commit d7a73c9

Browse files
authored
[LLVM][ADT] Put both vesions of 'unique' into STLExtras.h (#82312)
Currently there are two versions of llvm::unique, one that requires a predicate, and is in STLExtras.h; and one that does not require a predicate, and is in GenericUniformityImpl.h. This moves the one from GenericUniformityImp.h to STlExtras.h, so they are both together, and can both be easily called from other places inside LLVM.
1 parent 8ca351d commit d7a73c9

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

llvm/include/llvm/ADT/GenericUniformityImpl.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
#include "llvm/ADT/GenericUniformityInfo.h"
4848

49+
#include "llvm/ADT/STLExtras.h"
4950
#include "llvm/ADT/SmallPtrSet.h"
5051
#include "llvm/ADT/SparseBitVector.h"
5152
#include "llvm/ADT/StringExtras.h"
@@ -57,10 +58,6 @@
5758

5859
namespace llvm {
5960

60-
template <typename Range> auto unique(Range &&R) {
61-
return std::unique(adl_begin(R), adl_end(R));
62-
}
63-
6461
/// Construct a specially modified post-order traversal of cycles.
6562
///
6663
/// The ModifiedPO is contructed using a virtually modified CFG as follows:

llvm/include/llvm/ADT/STLExtras.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,6 +1994,12 @@ auto unique(Range &&R, Predicate P) {
19941994
return std::unique(adl_begin(R), adl_end(R), P);
19951995
}
19961996

1997+
/// Wrapper function around std::unique to allow calling unique on a
1998+
/// container without having to specify the begin/end iterators.
1999+
template <typename Range> auto unique(Range &&R) {
2000+
return std::unique(adl_begin(R), adl_end(R));
2001+
}
2002+
19972003
/// Wrapper function around std::equal to detect if pair-wise elements between
19982004
/// two ranges are the same.
19992005
template <typename L, typename R> bool equal(L &&LRange, R &&RRange) {

llvm/unittests/ADT/STLExtrasTest.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,19 @@ TEST(STLExtras, Unique) {
10041004
EXPECT_EQ(3, V[3]);
10051005
}
10061006

1007+
TEST(STLExtras, UniqueNoPred) {
1008+
std::vector<uint32_t> V = {1, 5, 5, 4, 3, 3, 3};
1009+
1010+
auto I = llvm::unique(V);
1011+
1012+
EXPECT_EQ(I, V.begin() + 4);
1013+
1014+
EXPECT_EQ(1, V[0]);
1015+
EXPECT_EQ(5, V[1]);
1016+
EXPECT_EQ(4, V[2]);
1017+
EXPECT_EQ(3, V[3]);
1018+
}
1019+
10071020
TEST(STLExtrasTest, MakeVisitorOneCallable) {
10081021
auto IdentityLambda = [](auto X) { return X; };
10091022
auto IdentityVisitor = makeVisitor(IdentityLambda);

0 commit comments

Comments
 (0)