Commit 9dfbfa1f authored by Xiao Shi's avatar Xiao Shi Committed by Facebook Github Bot

add F14 forward declaration as a separate header file

Summary:
This diff adds a header file which includes forward declaration of F14
containers.

Reviewed By: nbronson

Differential Revision: D7342805

fbshipit-source-id: 01e867792d8bde3769f4c71dfb6b80574b13f2b6
parent 77e4a6f1
......@@ -407,6 +407,7 @@ if (BUILD_TESTS)
# EnumerateTest.cpp since it uses macros to define tests.
#TEST enumerate_test SOURCES EnumerateTest.cpp
TEST evicting_cache_map_test SOURCES EvictingCacheMapTest.cpp
TEST f14_pre_test SOURCES F14PreTest.cpp
TEST f14_map_test SOURCES F14MapTest.cpp
TEST f14_set_test SOURCES F14SetTest.cpp
TEST foreach_test SOURCES ForeachTest.cpp
......
......@@ -59,6 +59,7 @@ nobase_follyinclude_HEADERS = \
container/Access.h \
container/Array.h \
container/detail/BitIteratorDetail.h \
container/detail/F14Defaults.h \
container/detail/F14IntrinsicsAvailability.h \
container/detail/F14Memory.h \
container/detail/F14Policy.h \
......@@ -66,7 +67,9 @@ nobase_follyinclude_HEADERS = \
container/Iterator.h \
container/Enumerate.h \
container/EvictingCacheMap.h \
container/F14Map-pre.h \
container/F14Map.h \
container/F14Set-pre.h \
container/F14Set.h \
container/Foreach.h \
container/Foreach-inl.h \
......
/*
* Copyright 2018-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <utility>
#include <folly/container/detail/F14Defaults.h>
namespace folly {
template <
typename K,
typename M,
typename H = f14::DefaultHasher<K>,
typename E = f14::DefaultKeyEqual<K>,
typename A = f14::DefaultAlloc<std::pair<K const, M>>>
class F14NodeMap;
template <
typename K,
typename M,
typename H = f14::DefaultHasher<K>,
typename E = f14::DefaultKeyEqual<K>,
typename A = f14::DefaultAlloc<std::pair<K const, M>>>
class F14ValueMap;
template <
typename K,
typename M,
typename H = f14::DefaultHasher<K>,
typename E = f14::DefaultKeyEqual<K>,
typename A = f14::DefaultAlloc<std::pair<K const, M>>>
class F14VectorMap;
template <
typename K,
typename M,
typename H = f14::DefaultHasher<K>,
typename E = f14::DefaultKeyEqual<K>,
typename A = f14::DefaultAlloc<std::pair<K const, M>>>
class F14FastMap;
} // namespace folly
......@@ -34,6 +34,7 @@
#include <folly/lang/Exception.h>
#include <folly/lang/SafeAssert.h>
#include <folly/container/F14Map-pre.h>
#include <folly/container/detail/F14Policy.h>
#include <folly/container/detail/F14Table.h>
......@@ -43,12 +44,7 @@
namespace folly {
template <
typename K,
typename M,
typename H = std::hash<K>,
typename E = std::equal_to<K>,
typename A = std::allocator<std::pair<K const, M>>>
template <typename K, typename M, typename H, typename E, typename A>
class F14ValueMap : public std::unordered_map<K, M, H, E, A> {
using Super = std::unordered_map<K, M, H, E, A>;
......@@ -57,12 +53,7 @@ class F14ValueMap : public std::unordered_map<K, M, H, E, A> {
F14ValueMap() : Super() {}
};
template <
typename K,
typename M,
typename H = std::hash<K>,
typename E = std::equal_to<K>,
typename A = std::allocator<std::pair<K const, M>>>
template <typename K, typename M, typename H, typename E, typename A>
class F14NodeMap : public std::unordered_map<K, M, H, E, A> {
using Super = std::unordered_map<K, M, H, E, A>;
......@@ -71,12 +62,7 @@ class F14NodeMap : public std::unordered_map<K, M, H, E, A> {
F14NodeMap() : Super() {}
};
template <
typename K,
typename M,
typename H = std::hash<K>,
typename E = std::equal_to<K>,
typename A = std::allocator<std::pair<K const, M>>>
template <typename K, typename M, typename H, typename E, typename A>
class F14VectorMap : public std::unordered_map<K, M, H, E, A> {
using Super = std::unordered_map<K, M, H, E, A>;
......@@ -757,9 +743,9 @@ bool mapsEqual(M const& lhs, M const& rhs) {
template <
typename Key,
typename Mapped,
typename Hasher = f14::DefaultHasher<Key>,
typename KeyEqual = f14::DefaultKeyEqual<Key>,
typename Alloc = f14::DefaultAlloc<std::pair<Key const, Mapped>>>
typename Hasher,
typename KeyEqual,
typename Alloc>
class F14ValueMap
: public f14::detail::F14BasicMap<f14::detail::MapPolicyWithDefaults<
f14::detail::ValueContainerPolicy,
......@@ -807,9 +793,9 @@ bool operator!=(
template <
typename Key,
typename Mapped,
typename Hasher = f14::DefaultHasher<Key>,
typename KeyEqual = f14::DefaultKeyEqual<Key>,
typename Alloc = f14::DefaultAlloc<std::pair<Key const, Mapped>>>
typename Hasher,
typename KeyEqual,
typename Alloc>
class F14NodeMap
: public f14::detail::F14BasicMap<f14::detail::MapPolicyWithDefaults<
f14::detail::NodeContainerPolicy,
......@@ -859,9 +845,9 @@ bool operator!=(
template <
typename Key,
typename Mapped,
typename Hasher = f14::DefaultHasher<Key>,
typename KeyEqual = f14::DefaultKeyEqual<Key>,
typename Alloc = f14::DefaultAlloc<std::pair<Key const, Mapped>>>
typename Hasher,
typename KeyEqual,
typename Alloc>
class F14VectorMap
: public f14::detail::F14BasicMap<f14::detail::MapPolicyWithDefaults<
f14::detail::VectorContainerPolicy,
......@@ -995,9 +981,9 @@ namespace folly {
template <
typename Key,
typename Mapped,
typename Hasher = f14::DefaultHasher<Key>,
typename KeyEqual = f14::DefaultKeyEqual<Key>,
typename Alloc = f14::DefaultAlloc<std::pair<Key const, Mapped>>>
typename Hasher,
typename KeyEqual,
typename Alloc>
class F14FastMap : public std::conditional_t<
sizeof(std::pair<Key const, Mapped>) < 24,
F14ValueMap<Key, Mapped, Hasher, KeyEqual, Alloc>,
......
/*
* Copyright 2018-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <folly/container/detail/F14Defaults.h>
namespace folly {
template <
typename K,
typename H = f14::DefaultHasher<K>,
typename E = f14::DefaultKeyEqual<K>,
typename A = f14::DefaultAlloc<K>>
class F14NodeSet;
template <
typename K,
typename H = f14::DefaultHasher<K>,
typename E = f14::DefaultKeyEqual<K>,
typename A = f14::DefaultAlloc<K>>
class F14ValueSet;
template <
typename K,
typename H = f14::DefaultHasher<K>,
typename E = f14::DefaultKeyEqual<K>,
typename A = f14::DefaultAlloc<K>>
class F14VectorSet;
template <
typename K,
typename H = f14::DefaultHasher<K>,
typename E = f14::DefaultKeyEqual<K>,
typename A = f14::DefaultAlloc<K>>
class F14FastSet;
} // namespace folly
......@@ -29,6 +29,7 @@
#include <folly/lang/SafeAssert.h>
#include <folly/container/F14Set-pre.h>
#include <folly/container/detail/F14Policy.h>
#include <folly/container/detail/F14Table.h>
......@@ -38,11 +39,7 @@
namespace folly {
template <
typename K,
typename H = std::hash<K>,
typename E = std::equal_to<K>,
typename A = std::allocator<K>>
template <typename K, typename H, typename E, typename A>
class F14NodeSet : public std::unordered_set<K, H, E, A> {
using Super = std::unordered_set<K, H, E, A>;
......@@ -51,11 +48,7 @@ class F14NodeSet : public std::unordered_set<K, H, E, A> {
F14NodeSet() : Super() {}
};
template <
typename K,
typename H = std::hash<K>,
typename E = std::equal_to<K>,
typename A = std::allocator<K>>
template <typename K, typename H, typename E, typename A>
class F14ValueSet : public std::unordered_set<K, H, E, A> {
using Super = std::unordered_set<K, H, E, A>;
......@@ -64,11 +57,7 @@ class F14ValueSet : public std::unordered_set<K, H, E, A> {
F14ValueSet() : Super() {}
};
template <
typename K,
typename H = std::hash<K>,
typename E = std::equal_to<K>,
typename A = std::allocator<K>>
template <typename K, typename H, typename E, typename A>
class F14VectorSet : public std::unordered_set<K, H, E, A> {
using Super = std::unordered_set<K, H, E, A>;
......@@ -536,11 +525,7 @@ bool setsEqual(S const& lhs, S const& rhs) {
} // namespace detail
} // namespace f14
template <
typename Key,
typename Hasher = f14::DefaultHasher<Key>,
typename KeyEqual = f14::DefaultKeyEqual<Key>,
typename Alloc = f14::DefaultAlloc<Key>>
template <typename Key, typename Hasher, typename KeyEqual, typename Alloc>
class F14ValueSet
: public f14::detail::F14BasicSet<f14::detail::SetPolicyWithDefaults<
f14::detail::ValueContainerPolicy,
......@@ -583,11 +568,7 @@ bool operator!=(
return !(lhs == rhs);
}
template <
typename Key,
typename Hasher = f14::DefaultHasher<Key>,
typename KeyEqual = f14::DefaultKeyEqual<Key>,
typename Alloc = f14::DefaultAlloc<Key>>
template <typename Key, typename Hasher, typename KeyEqual, typename Alloc>
class F14NodeSet
: public f14::detail::F14BasicSet<f14::detail::SetPolicyWithDefaults<
f14::detail::NodeContainerPolicy,
......@@ -630,11 +611,7 @@ bool operator!=(
return !(lhs == rhs);
}
template <
typename Key,
typename Hasher = f14::DefaultHasher<Key>,
typename KeyEqual = f14::DefaultKeyEqual<Key>,
typename Alloc = f14::DefaultAlloc<Key>>
template <typename Key, typename Hasher, typename KeyEqual, typename Alloc>
class F14VectorSet
: public f14::detail::F14BasicSet<f14::detail::SetPolicyWithDefaults<
f14::detail::VectorContainerPolicy,
......@@ -756,11 +733,7 @@ bool operator!=(
#endif // FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
namespace folly {
template <
typename Key,
typename Hasher = f14::DefaultHasher<Key>,
typename KeyEqual = f14::DefaultKeyEqual<Key>,
typename Alloc = f14::DefaultAlloc<Key>>
template <typename Key, typename Hasher, typename KeyEqual, typename Alloc>
class F14FastSet : public std::conditional_t<
sizeof(Key) < 24,
F14ValueSet<Key, Hasher, KeyEqual, Alloc>,
......
/*
* Copyright 2018-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <functional>
#include <memory>
namespace folly {
namespace f14 {
template <typename T>
using DefaultHasher = std::hash<T>;
template <typename T>
using DefaultKeyEqual = std::equal_to<T>;
template <typename T>
using DefaultAlloc = std::allocator<T>;
} // namespace f14
} // namespace folly
......@@ -42,6 +42,7 @@
#include <folly/portability/Builtins.h>
#include <folly/portability/TypeTraits.h>
#include <folly/container/detail/F14Defaults.h>
#include <folly/container/detail/F14IntrinsicsAvailability.h>
#include <folly/container/detail/F14Memory.h>
......@@ -87,17 +88,6 @@ struct F14TableStats {
}
};
namespace f14 {
template <typename T>
using DefaultHasher = std::hash<T>;
template <typename T>
using DefaultKeyEqual = std::equal_to<T>;
template <typename T>
using DefaultAlloc = std::allocator<T>;
} // namespace f14
#if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
namespace f14 {
namespace detail {
......
/*
* Copyright 2018-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <folly/container/F14Map-pre.h>
#include <folly/container/F14Set-pre.h>
#include <folly/portability/GTest.h>
namespace {
template <typename TContainer>
void foo(TContainer*) {}
} // namespace
TEST(F14Pre, simple) {
using namespace folly;
foo<F14NodeMap<int, int>>(nullptr);
foo<F14ValueMap<int, int>>(nullptr);
foo<F14VectorMap<int, int>>(nullptr);
foo<F14FastMap<int, int>>(nullptr);
foo<F14NodeSet<int>>(nullptr);
foo<F14ValueSet<int>>(nullptr);
foo<F14VectorSet<int>>(nullptr);
foo<F14FastSet<int>>(nullptr);
}
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