Commit c8eeea45 authored by Jack Montgomery's avatar Jack Montgomery Committed by Facebook Github Bot

Add data() method to folly sorted vector types

Summary: Add a data() method to folly::sorted_vector_map and folly::sorted_vector_set which returns a const pointer to the underlying container's data

Reviewed By: yfeldblum

Differential Revision: D8750840

fbshipit-source-id: d361fe21ac741b31b60f551935a3ed8c9549f11a
parent 16b84942
......@@ -487,6 +487,10 @@ class sorted_vector_set
return m_.cont_ < other.m_.cont_;
}
const value_type* data() const noexcept {
return m_.cont_.data();
}
private:
/*
* This structure derives from the comparison object in order to
......@@ -840,6 +844,10 @@ class sorted_vector_map
return m_.cont_ < other.m_.cont_;
}
const value_type* data() const noexcept {
return m_.cont_.data();
}
private:
// This is to get the empty base optimization; see the comment in
// sorted_vector_set.
......
......@@ -773,3 +773,18 @@ TEST(SortedVectorTypes, TestBulkInsertionWithDuplicatesIntoEmptySet) {
}
EXPECT_THAT(set, testing::ElementsAreArray({0, 1}));
}
TEST(SortedVectorTypes, TestDataPointsToFirstElement) {
sorted_vector_set<int> set;
sorted_vector_map<int, int> map;
set.insert(0);
map[0] = 0;
EXPECT_EQ(set.data(), &*set.begin());
EXPECT_EQ(map.data(), &*map.begin());
set.insert(1);
map[1] = 1;
EXPECT_EQ(set.data(), &*set.begin());
EXPECT_EQ(map.data(), &*map.begin());
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment