Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit a481451

Browse files
author
Zachary Turner
committed
Revert "Add llvm::enumerate() to STLExtras."
This reverts commit r282804 as it seems to use some C++ features that not all compilers support. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282809 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent ab82a45 commit a481451

File tree

2 files changed

+0
-116
lines changed

2 files changed

+0
-116
lines changed

include/llvm/ADT/STLExtras.h

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -626,73 +626,6 @@ template <typename T> struct deref {
626626
}
627627
};
628628

629-
namespace detail {
630-
template <typename I, typename V> class enumerator_impl {
631-
public:
632-
template <typename V> struct result_pair {
633-
result_pair(std::size_t Index, V Value) : Index(Index), Value(Value) {}
634-
635-
const std::size_t Index;
636-
V Value;
637-
};
638-
639-
template <typename I, typename V> struct iterator {
640-
iterator(I Iter, std::size_t Index) : Iter(Iter), Index(Index) {}
641-
642-
result_pair<const V> operator*() const {
643-
return result_pair<const V>(Index, *Iter);
644-
}
645-
result_pair<V> operator*() { return result_pair<V>(Index, *Iter); }
646-
647-
iterator &operator++() {
648-
++Iter;
649-
++Index;
650-
return *this;
651-
}
652-
653-
bool operator!=(const iterator &RHS) const { return Iter != RHS.Iter; }
654-
655-
private:
656-
I Iter;
657-
std::size_t Index;
658-
};
659-
660-
enumerator_impl(I Begin, I End)
661-
: Begin(std::move(Begin)), End(std::move(End)) {}
662-
663-
iterator<I, V> begin() { return iterator<I, V>(Begin, 0); }
664-
iterator<I, V> end() { return iterator<I, V>(End, std::size_t(-1)); }
665-
666-
iterator<I, V> begin() const { return iterator<I, V>(Begin, 0); }
667-
iterator<I, V> end() const { return iterator<I, V>(End, std::size_t(-1)); }
668-
669-
private:
670-
I Begin;
671-
I End;
672-
};
673-
}
674-
675-
/// Given an input range, returns a new range whose values are are pair (A,B)
676-
/// such that A is the 0-based index of the item in the sequence, and B is
677-
/// the value from the original sequence. Example:
678-
///
679-
/// std::vector<char> Items = {'A', 'B', 'C', 'D'};
680-
/// for (auto X : enumerate(Items)) {
681-
/// printf("Item %d - %c\n", X.Item, X.Value);
682-
/// }
683-
///
684-
/// Output:
685-
/// Item 0 - A
686-
/// Item 1 - B
687-
/// Item 2 - C
688-
/// Item 3 - D
689-
///
690-
template <typename R> auto enumerate(R &&Range) {
691-
typedef decltype(std::begin(Range)) I;
692-
typedef decltype(*std::begin(Range)) V;
693-
return detail::enumerator_impl<I, V>(std::begin(Range), std::end(Range));
694-
}
695-
696629
} // End llvm namespace
697630

698631
#endif

unittests/ADT/STLExtrasTest.cpp

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include "llvm/ADT/STLExtras.h"
1111
#include "gtest/gtest.h"
1212

13-
#include <vector>
14-
1513
using namespace llvm;
1614

1715
namespace {
@@ -39,51 +37,4 @@ TEST(STLExtrasTest, Rank) {
3937
EXPECT_EQ(4, f(rank<6>()));
4038
}
4139

42-
TEST(STLExtrasTest, Enumerate) {
43-
std::vector<char> foo = {'a', 'b', 'c'};
44-
45-
std::vector<std::pair<std::size_t, char>> results;
46-
47-
for (auto X : llvm::enumerate(foo)) {
48-
results.push_back(std::make_pair(X.Index, X.Value));
49-
}
50-
ASSERT_EQ(3, results.size());
51-
EXPECT_EQ(0, results[0].first);
52-
EXPECT_EQ('a', results[0].second);
53-
EXPECT_EQ(1, results[1].first);
54-
EXPECT_EQ('b', results[1].second);
55-
EXPECT_EQ(2, results[2].first);
56-
EXPECT_EQ('c', results[2].second);
57-
58-
results.clear();
59-
const std::vector<int> bar = {'1', '2', '3'};
60-
for (auto X : llvm::enumerate(bar)) {
61-
results.push_back(std::make_pair(X.Index, X.Value));
62-
}
63-
EXPECT_EQ(0, results[0].first);
64-
EXPECT_EQ('1', results[0].second);
65-
EXPECT_EQ(1, results[1].first);
66-
EXPECT_EQ('2', results[1].second);
67-
EXPECT_EQ(2, results[2].first);
68-
EXPECT_EQ('3', results[2].second);
69-
70-
results.clear();
71-
const std::vector<int> baz;
72-
for (auto X : llvm::enumerate(baz)) {
73-
results.push_back(std::make_pair(X.Index, X.Value));
74-
}
75-
EXPECT_TRUE(baz.empty());
76-
}
77-
78-
TEST(STLExtrasTest, EnumerateModify) {
79-
std::vector<char> foo = {'a', 'b', 'c'};
80-
81-
for (auto X : llvm::enumerate(foo)) {
82-
++X.Value;
83-
}
84-
85-
EXPECT_EQ('b', foo[0]);
86-
EXPECT_EQ('c', foo[1]);
87-
EXPECT_EQ('d', foo[2]);
88-
}
8940
}

0 commit comments

Comments
 (0)