Skip to content

Commit ee2ca36

Browse files
authored
Firestore: Fix Windows build due to decltype of captured lambda (#10237)
1 parent 5d7d52c commit ee2ca36

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

Firestore/core/src/local/local_store.cc

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -662,23 +662,18 @@ absl::optional<bundle::NamedQuery> LocalStore::GetNamedQuery(
662662

663663
void LocalStore::ConfigureFieldIndexes(
664664
std::vector<FieldIndex> new_field_indexes) {
665-
auto cmp = [](const FieldIndex& left, const FieldIndex& right) {
666-
return FieldIndex::SemanticCompare(left, right) ==
667-
util::ComparisonResult::Ascending;
668-
};
669-
670665
// This lambda function takes a rvalue vector as parameter,
671666
// then coverts it to a sorted set based on the compare function above.
672-
auto convertToSet = [&](std::vector<FieldIndex>&& vec) {
673-
std::set<FieldIndex, decltype(cmp)> result(cmp);
667+
auto convertToSet = [](std::vector<FieldIndex>&& vec) {
668+
std::set<FieldIndex, FieldIndex::SemanticLess> result;
674669
for (auto& index : vec) {
675670
result.insert(std::move(index));
676671
}
677672
return result;
678673
};
679674

680675
return persistence_->Run("Configure indexes", [&] {
681-
return util::DiffSets<FieldIndex, decltype(cmp)>(
676+
return util::DiffSets<FieldIndex, FieldIndex::SemanticLess>(
682677
convertToSet(index_manager_->GetFieldIndexes()),
683678
convertToSet(std::move(new_field_indexes)), FieldIndex::SemanticCompare,
684679
[this](const model::FieldIndex& index) {

Firestore/core/src/model/field_index.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,21 @@ class FieldIndex {
285285
/** Returns the ArrayContains/ArrayContainsAny segment for this index. */
286286
absl::optional<Segment> GetArraySegment() const;
287287

288+
/**
289+
* A type that can be used as the "Compare" template parameter of ordered
290+
* collections to have the elements ordered using
291+
* `FieldIndex::SemanticCompare()`.
292+
*
293+
* Example:
294+
* std::set<FieldIndex, FieldIndex::SemanticLess> result;
295+
*/
296+
struct SemanticLess {
297+
bool operator()(const FieldIndex& left, const FieldIndex& right) const {
298+
return FieldIndex::SemanticCompare(left, right) ==
299+
util::ComparisonResult::Ascending;
300+
}
301+
};
302+
288303
private:
289304
friend bool operator==(const FieldIndex& lhs, const FieldIndex& rhs);
290305
friend bool operator!=(const FieldIndex& lhs, const FieldIndex& rhs);

Firestore/core/test/unit/local/leveldb_local_store_test.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,7 @@ std::unique_ptr<LocalStoreTestHelper> Factory() {
6969
// This lambda function takes a rvalue vector as parameter,
7070
// then coverts it to a sorted set based on the compare function.
7171
auto convertToSet = [](std::vector<FieldIndex>&& vec) {
72-
auto cmp = [](const FieldIndex& left, const FieldIndex& right) {
73-
return FieldIndex::SemanticCompare(left, right) ==
74-
util::ComparisonResult::Ascending;
75-
};
76-
77-
std::set<FieldIndex, decltype(cmp)> result(cmp);
72+
std::set<FieldIndex, FieldIndex::SemanticLess> result;
7873
for (auto& index : vec) {
7974
result.insert(std::move(index));
8075
}

0 commit comments

Comments
 (0)