Skip to content

Commit

Permalink
Enable deduction guides for F14{Map,Set}Fallback
Browse files Browse the repository at this point in the history
Summary:
`F14*` should mimic `std::unordered_*` containers (this is true for
constructor set as well), so we should be fine re-using same deduction guides
we use for main implementation.

Moved include of `F14*Fallback.h` headers on top of the file and made
`FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE` defines more granular to share
same deduction guides between two implementations.

Reviewed By: yfeldblum, ot

Differential Revision: D52604127

fbshipit-source-id: 820ee12a4a1a9c7c5607a049fcfc3ccdcf56acdc
  • Loading branch information
ilvokhin authored and facebook-github-bot committed Jan 12, 2024
1 parent 2cf8c88 commit 7646712
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
16 changes: 10 additions & 6 deletions folly/container/F14Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@

#include <folly/container/F14Map-fwd.h>
#include <folly/container/Iterator.h>
#include <folly/container/detail/F14MapFallback.h>
#include <folly/container/detail/F14Policy.h>
#include <folly/container/detail/F14Table.h>
#include <folly/container/detail/Util.h>

namespace folly {

#if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE

//////// Common case for supported platforms

namespace folly {
namespace f14 {
namespace detail {

Expand Down Expand Up @@ -1114,6 +1116,7 @@ class F14ValueMap
this->table_.visitContiguousItemRanges(visitor);
}
};
#endif // FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE

template <
typename InputIt,
Expand Down Expand Up @@ -1199,6 +1202,7 @@ F14ValueMap(
std::initializer_list<std::pair<Key, Mapped>>, std::size_t, Hasher, Alloc)
-> F14ValueMap<Key, Mapped, Hasher, f14::DefaultKeyEqual<Key>, Alloc>;

#if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
template <
typename Key,
typename Mapped,
Expand Down Expand Up @@ -1261,6 +1265,7 @@ class F14NodeMap

// TODO extract and node_handle insert
};
#endif // FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE

template <
typename InputIt,
Expand Down Expand Up @@ -1345,6 +1350,7 @@ F14NodeMap(
std::initializer_list<std::pair<Key, Mapped>>, std::size_t, Hasher, Alloc)
-> F14NodeMap<Key, Mapped, Hasher, f14::DefaultKeyEqual<Key>, Alloc>;

#if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
namespace f14 {
namespace detail {
template <
Expand Down Expand Up @@ -1666,6 +1672,7 @@ class F14VectorMap : public f14::detail::F14VectorMapImpl<
return {c.rbegin(), c.rend()};
}
};
#endif // FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE

template <
typename InputIt,
Expand Down Expand Up @@ -1750,6 +1757,7 @@ F14VectorMap(
std::initializer_list<std::pair<Key, Mapped>>, std::size_t, Hasher, Alloc)
-> F14VectorMap<Key, Mapped, Hasher, f14::DefaultKeyEqual<Key>, Alloc>;

#if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
/**
* F14FastMap is, under the hood, either an F14ValueMap or an F14VectorMap.
* F14FastMap chooses which of these two representations to use based on the
Expand Down Expand Up @@ -1799,6 +1807,7 @@ class F14FastMap : public std::conditional_t<
this->table_.swap(rhs.table_);
}
};
#endif // if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE

template <
typename InputIt,
Expand Down Expand Up @@ -1885,11 +1894,6 @@ F14FastMap(

} // namespace folly

#endif // if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE

//////// Compatibility for unsupported platforms (not x86_64 and not aarch64)
#include <folly/container/detail/F14MapFallback.h>

namespace folly {
namespace f14 {
namespace detail {
Expand Down
16 changes: 10 additions & 6 deletions folly/container/F14Set.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@
#include <folly/container/F14Set-fwd.h>
#include <folly/container/Iterator.h>
#include <folly/container/detail/F14Policy.h>
#include <folly/container/detail/F14SetFallback.h>
#include <folly/container/detail/F14Table.h>
#include <folly/container/detail/Util.h>

namespace folly {

#if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE

//////// Common case for supported platforms

namespace folly {
namespace f14 {
namespace detail {

Expand Down Expand Up @@ -843,6 +845,7 @@ class F14ValueSet
this->table_.visitContiguousItemRanges(std::forward<V>(visitor));
}
};
#endif // FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE

template <
typename InputIt,
Expand Down Expand Up @@ -914,6 +917,7 @@ template <
F14ValueSet(std::initializer_list<Key>, std::size_t, Hasher, Alloc)
-> F14ValueSet<Key, Hasher, f14::DefaultKeyEqual<Key>, Alloc>;

#if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
template <typename Key, typename Hasher, typename KeyEqual, typename Alloc>
class F14NodeSet
: public f14::detail::F14BasicSet<f14::detail::SetPolicyWithDefaults<
Expand Down Expand Up @@ -957,6 +961,7 @@ class F14NodeSet
});
}
};
#endif // FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE

template <
typename InputIt,
Expand Down Expand Up @@ -1028,6 +1033,7 @@ template <
F14NodeSet(std::initializer_list<Key>, std::size_t, Hasher, Alloc)
-> F14NodeSet<Key, Hasher, f14::DefaultKeyEqual<Key>, Alloc>;

#if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
namespace f14 {
namespace detail {
template <
Expand Down Expand Up @@ -1271,6 +1277,7 @@ class F14VectorSet
return {c.rbegin(), c.rend()};
}
};
#endif // FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE

template <
typename InputIt,
Expand Down Expand Up @@ -1342,6 +1349,7 @@ template <
F14VectorSet(std::initializer_list<Key>, std::size_t, Hasher, Alloc)
-> F14VectorSet<Key, Hasher, f14::DefaultKeyEqual<Key>, Alloc>;

#if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
template <typename Key, typename Hasher, typename KeyEqual, typename Alloc>
class F14FastSet
: public std::conditional_t<
Expand Down Expand Up @@ -1371,6 +1379,7 @@ class F14FastSet
this->table_.swap(rhs.table_);
}
};
#endif // FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE

template <
typename InputIt,
Expand Down Expand Up @@ -1444,11 +1453,6 @@ F14FastSet(std::initializer_list<Key>, std::size_t, Hasher, Alloc)

} // namespace folly

#endif // if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE

//////// Compatibility for unsupported platforms (not x86_64 and not aarch64)
#include <folly/container/detail/F14SetFallback.h>

namespace folly {
namespace f14 {
namespace detail {
Expand Down
3 changes: 0 additions & 3 deletions folly/container/test/F14MapTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2225,8 +2225,6 @@ TEST(F14Map, copyAfterRemovedCollisions) {
testCopyAfterRemovedCollisions<F14FastMap>();
}

#if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
// TODO: Implement deduction guides in fallback implementation.
template <template <class...> class TMap>
void testIterDeductionGuide() {
TMap<int, double> source({{1, 2.0}, {3, 4.0}});
Expand Down Expand Up @@ -2349,7 +2347,6 @@ TEST(F14Map, initializerListDeductionGuide) {
testInitializerListDeductionGuide<F14VectorMap>();
testInitializerListDeductionGuide<F14FastMap>();
}
#endif // FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE

namespace {

Expand Down
3 changes: 0 additions & 3 deletions folly/container/test/F14SetTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1599,8 +1599,6 @@ TEST(F14Set, ExceptionOnInsert) {
testExceptionOnInsert<F14FastSet>();
}

#if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
// TODO: Implement deduction guides in fallback implementation.
template <template <class...> class TSet>
void testIterDeductionGuide() {
TSet<int> source({1, 2});
Expand Down Expand Up @@ -1697,4 +1695,3 @@ TEST(F14Set, initializerListDeductionGuide) {
testInitializerListDeductionGuide<F14VectorSet>();
testInitializerListDeductionGuide<F14FastSet>();
}
#endif // FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE

0 comments on commit 7646712

Please sign in to comment.