Skip to content

[LLVM][ADT] Put both vesions of 'unique' into STLExtras.h #82312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions llvm/include/llvm/ADT/GenericUniformityImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

#include "llvm/ADT/GenericUniformityInfo.h"

#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SparseBitVector.h"
#include "llvm/ADT/StringExtras.h"
Expand All @@ -57,10 +58,6 @@

namespace llvm {

template <typename Range> auto unique(Range &&R) {
return std::unique(adl_begin(R), adl_end(R));
}

/// Construct a specially modified post-order traversal of cycles.
///
/// The ModifiedPO is contructed using a virtually modified CFG as follows:
Expand Down
6 changes: 6 additions & 0 deletions llvm/include/llvm/ADT/STLExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,12 @@ auto unique(Range &&R, Predicate P) {
return std::unique(adl_begin(R), adl_end(R), P);
}

/// Wrapper function around std::unique to allow calling unique on a
/// container without having to specify the begin/end iterators.
template <typename Range> auto unique(Range &&R) {
return std::unique(adl_begin(R), adl_end(R));
}

/// Wrapper function around std::equal to detect if pair-wise elements between
/// two ranges are the same.
template <typename L, typename R> bool equal(L &&LRange, R &&RRange) {
Expand Down
13 changes: 13 additions & 0 deletions llvm/unittests/ADT/STLExtrasTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,19 @@ TEST(STLExtras, Unique) {
EXPECT_EQ(3, V[3]);
}

TEST(STLExtras, UniqueNoPred) {
std::vector<uint32_t> V = {1, 5, 5, 4, 3, 3, 3};

auto I = llvm::unique(V);

EXPECT_EQ(I, V.begin() + 4);

EXPECT_EQ(1, V[0]);
EXPECT_EQ(5, V[1]);
EXPECT_EQ(4, V[2]);
EXPECT_EQ(3, V[3]);
}

TEST(STLExtrasTest, MakeVisitorOneCallable) {
auto IdentityLambda = [](auto X) { return X; };
auto IdentityVisitor = makeVisitor(IdentityLambda);
Expand Down