28 struct IsConstReference {
29 constexpr
static bool value =
false;
32 struct IsConstReference<
const T&> {
33 constexpr
static bool value =
true;
38 #define ENUMERATE_TEST_BASIC(DECL, NAME) \ 39 TEST(Enumerate, NAME) { \ 40 std::vector<std::string> v = {"abc", "a", "ab"}; \ 42 for (DECL it : folly::enumerate(v)) { \ 43 EXPECT_EQ(it.index, i); \ 44 EXPECT_EQ(*it, v[i]); \ 45 EXPECT_EQ(it->size(), v[i].size()); \ 48 std::string newValue = "x"; \ 50 EXPECT_EQ(newValue, v[i]); \ 55 EXPECT_EQ(i, v.size()); \ 61 #undef ENUMERATE_TEST_BASIC 63 #define ENUMERATE_TEST_BASIC_CONST(DECL, NAME) \ 64 TEST(Enumerate, NAME) { \ 65 std::vector<std::string> v = {"abc", "a", "ab"}; \ 67 for (DECL it : folly::enumerate(v)) { \ 69 IsConstReference<decltype(*it)>::value, "Const enumeration"); \ 70 EXPECT_EQ(it.index, i); \ 71 EXPECT_EQ(*it, v[i]); \ 72 EXPECT_EQ(it->size(), v[i].size()); \ 76 EXPECT_EQ(i, v.size()); \ 83 #undef ENUMERATE_TEST_BASIC_CONST 85 TEST(Enumerate, Temporary) {
86 std::vector<std::string>
v = {
"abc",
"a",
"ab"};
98 TEST(Enumerate, BasicConstArg) {
99 const std::vector<std::string>
v = {
"abc",
"a",
"ab"};
103 IsConstReference<decltype(*it)>::
value,
"Enumerating a const vector");
113 TEST(Enumerate, TemporaryConstEnumerate) {
114 std::vector<std::string>
v = {
"abc",
"a",
"ab"};
117 static_assert(IsConstReference<decltype(*it)>::
value,
"Const enumeration");
127 TEST(Enumerate, RangeSupport) {
128 std::vector<std::string>
v = {
"abc",
"a",
"ab"};
141 std::vector<std::string>
v;
168 TEST(Enumerate, Cpp17Support) {
169 std::array<char, 5>
test = {
"test"};
178 const auto&& it = *
begin;
#define ENUMERATE_TEST_BASIC(DECL, NAME)
const char * begin() const
bool operator==(const char *c, CStringRange::Sentinel)
#define ASSERT_LT(val1, val2)
#define EXPECT_EQ(val1, val2)
auto begin(TestAdlIterable &instance)
CStringRange(const char *cstr_)
auto end(TestAdlIterable &instance)
constexpr Range< Iter > range(Iter first, Iter last)
static const char *const value
detail::RangeEnumerator< Range > enumerate(Range &&r)
#define ENUMERATE_TEST_BASIC_CONST(DECL, NAME)