From 03a4c5bd8fc60ce0bed9531fcd88b06c06cb27cc Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Tue, 3 Jan 2017 13:44:19 -0800 Subject: [PATCH] Drop the boost dependency from Traits.h and FBVector.h Summary: [Folly] Drop the `boost` dependency from `Traits.h` and `FBVector.h`. Should not need it anymore with the currently supported compilers. Reviewed By: ericniebler Differential Revision: D4375572 fbshipit-source-id: df890c07f49b0499d2d2d08aa21c226b2893281e --- folly/FBVector.h | 7 +-- folly/MPMCQueue.h | 22 +++++---- folly/Makefile.am | 1 - folly/String.h | 8 ---- folly/Traits.h | 101 +++++++++++++---------------------------- folly/docs/FBVector.md | 27 ----------- folly/docs/Traits.md | 36 +++++---------- 7 files changed, 59 insertions(+), 143 deletions(-) diff --git a/folly/FBVector.h b/folly/FBVector.h index 2be7d9ff..c0ef1d43 100644 --- a/folly/FBVector.h +++ b/folly/FBVector.h @@ -210,7 +210,7 @@ public: private: typedef std::integral_constant::value && + IsTriviallyCopyable::value && sizeof(T) <= 16 // don't force large structures to be passed by value > should_pass_by_value; typedef typename std::conditional< @@ -322,7 +322,8 @@ private: void M_destroy(T* p) noexcept { if (usingStdAllocator::value) { - if (!boost::has_trivial_destructor::value) p->~T(); + if (!std::is_trivially_destructible::value) + p->~T(); } else { std::allocator_traits::destroy(impl_, p); } @@ -360,7 +361,7 @@ private: // optimized static void S_destroy_range(T* first, T* last) noexcept { - if (!boost::has_trivial_destructor::value) { + if (!std::is_trivially_destructible::value) { // EXPERIMENTAL DATA on fbvector> (where each vector has // size 0). // The unrolled version seems to work faster for small to medium sized diff --git a/folly/MPMCQueue.h b/folly/MPMCQueue.h index 74899ae8..dfeceb6e 100644 --- a/folly/MPMCQueue.h +++ b/folly/MPMCQueue.h @@ -86,7 +86,7 @@ template class MPMCQueueBase; /// use noexcept, you will have to wrap it in something that provides /// the guarantee. We provide an alternate safe implementation for types /// that don't use noexcept but that are marked folly::IsRelocatable -/// and boost::has_nothrow_constructor, which is common for folly types. +/// and std::is_nothrow_constructible, which is common for folly types. /// In particular, if you can declare FOLLY_ASSUME_FBVECTOR_COMPATIBLE /// then your type can be put in MPMCQueue. /// @@ -1310,15 +1310,17 @@ struct SingleElementQueue { /// enqueue using move construction, either real (if /// is_nothrow_move_constructible) or simulated using relocation and - /// default construction (if IsRelocatable and has_nothrow_constructor) - template ::value && - boost::has_nothrow_constructor::value) || - std::is_nothrow_constructible::value>::type> - void enqueue(const uint32_t turn, - Atom& spinCutoff, - const bool updateSpinCutoff, - T&& goner) noexcept { + /// default construction (if IsRelocatable and is_nothrow_constructible) + template < + typename = typename std::enable_if< + (folly::IsRelocatable::value && + std::is_nothrow_constructible::value) || + std::is_nothrow_constructible::value>::type> + void enqueue( + const uint32_t turn, + Atom& spinCutoff, + const bool updateSpinCutoff, + T&& goner) noexcept { enqueueImpl( turn, spinCutoff, diff --git a/folly/Makefile.am b/folly/Makefile.am index d0416648..52cb69fa 100644 --- a/folly/Makefile.am +++ b/folly/Makefile.am @@ -8,7 +8,6 @@ ACLOCAL_AMFLAGS = -I m4 CLEANFILES = - noinst_PROGRAMS = generate_fingerprint_tables generate_fingerprint_tables_SOURCES = build/GenerateFingerprintTables.cpp generate_fingerprint_tables_LDADD = libfollybase.la diff --git a/folly/String.h b/folly/String.h index c9982f35..46882e68 100644 --- a/folly/String.h +++ b/folly/String.h @@ -646,12 +646,4 @@ using UTF8StringPiece = UTF8Range; } // namespace folly -// Hook into boost's type traits -namespace boost { -template -struct has_nothrow_constructor > : true_type { - enum { value = true }; -}; -} // namespace boost - #include diff --git a/folly/Traits.h b/folly/Traits.h index a038b18c..ed257430 100644 --- a/folly/Traits.h +++ b/folly/Traits.h @@ -36,8 +36,6 @@ #include #endif -#include - #define FOLLY_CREATE_HAS_MEMBER_TYPE_TRAITS(classname, type_name) \ template \ struct classname##__folly_traits_impl__ { \ @@ -341,29 +339,12 @@ using StrictConjunction = struct IsRelocatable< __VA_ARGS__ > : std::true_type {}; /** - * Use this macro ONLY inside namespace boost. When using it with a - * regular type, use it like this: - * - * // Make sure you're at namespace ::boost scope - * template<> FOLLY_ASSUME_HAS_NOTHROW_CONSTRUCTOR(MyType) - * - * When using it with a template type, use it like this: - * - * // Make sure you're at namespace ::boost scope - * template - * FOLLY_ASSUME_HAS_NOTHROW_CONSTRUCTOR(MyType) - */ -#define FOLLY_ASSUME_HAS_NOTHROW_CONSTRUCTOR(...) \ - struct has_nothrow_constructor< __VA_ARGS__ > : ::boost::true_type {}; - -/** - * The FOLLY_ASSUME_FBVECTOR_COMPATIBLE* macros below encode two - * assumptions: first, that the type is relocatable per IsRelocatable - * above, and that it has a nothrow constructor. Most types can be - * assumed to satisfy both conditions, but it is the responsibility of - * the user to state that assumption. User-defined classes will not - * work with fbvector (see FBVector.h) unless they state this - * combination of properties. + * The FOLLY_ASSUME_FBVECTOR_COMPATIBLE* macros below encode the + * assumption that the type is relocatable per IsRelocatable + * above. Many types can be assumed to satisfy this condition, but + * it is the responsibility of the user to state that assumption. + * User-defined classes will not be optimized for use with + * fbvector (see FBVector.h) unless they state that assumption. * * Use FOLLY_ASSUME_FBVECTOR_COMPATIBLE with regular types like this: * @@ -382,40 +363,35 @@ using StrictConjunction = */ // Use this macro ONLY at global level (no namespace) -#define FOLLY_ASSUME_FBVECTOR_COMPATIBLE(...) \ - namespace folly { template<> FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__) } \ - namespace boost { \ - template<> FOLLY_ASSUME_HAS_NOTHROW_CONSTRUCTOR(__VA_ARGS__) } +#define FOLLY_ASSUME_FBVECTOR_COMPATIBLE(...) \ + namespace folly { \ + template <> \ + FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__) \ + } // Use this macro ONLY at global level (no namespace) -#define FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(...) \ - namespace folly { \ - template FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__) } \ - namespace boost { \ - template FOLLY_ASSUME_HAS_NOTHROW_CONSTRUCTOR(__VA_ARGS__) } +#define FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(...) \ + namespace folly { \ + template \ + FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__) \ + } // Use this macro ONLY at global level (no namespace) -#define FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(...) \ - namespace folly { \ - template \ - FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__) } \ - namespace boost { \ - template \ - FOLLY_ASSUME_HAS_NOTHROW_CONSTRUCTOR(__VA_ARGS__) } +#define FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(...) \ + namespace folly { \ + template \ + FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__) \ + } // Use this macro ONLY at global level (no namespace) -#define FOLLY_ASSUME_FBVECTOR_COMPATIBLE_3(...) \ - namespace folly { \ - template \ - FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__) } \ - namespace boost { \ - template \ - FOLLY_ASSUME_HAS_NOTHROW_CONSTRUCTOR(__VA_ARGS__) } +#define FOLLY_ASSUME_FBVECTOR_COMPATIBLE_3(...) \ + namespace folly { \ + template \ + FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__) \ + } // Use this macro ONLY at global level (no namespace) -#define FOLLY_ASSUME_FBVECTOR_COMPATIBLE_4(...) \ - namespace folly { \ - template \ - FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__) } \ - namespace boost { \ - template \ - FOLLY_ASSUME_HAS_NOTHROW_CONSTRUCTOR(__VA_ARGS__) } +#define FOLLY_ASSUME_FBVECTOR_COMPATIBLE_4(...) \ + namespace folly { \ + template \ + FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__) \ + } /** * Instantiate FOLLY_ASSUME_FBVECTOR_COMPATIBLE for a few types. It is @@ -454,18 +430,6 @@ template FOLLY_NAMESPACE_STD_END -namespace boost { - -template class shared_ptr; - -template -struct has_nothrow_constructor< std::pair > - : std::integral_constant::value && - has_nothrow_constructor::value> {}; - -} // namespace boost - namespace folly { // STL commonly-used types @@ -681,9 +645,6 @@ FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(std::deque) FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(std::unique_ptr) FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(std::shared_ptr) FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(std::function) - -// Boost -FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(boost::shared_ptr) #endif /* Some combinations of compilers and C++ libraries make __int128 and diff --git a/folly/docs/FBVector.md b/folly/docs/FBVector.md index c76d645e..792aa0a0 100644 --- a/folly/docs/FBVector.md +++ b/folly/docs/FBVector.md @@ -189,33 +189,6 @@ after `Widget`'s definition and write this: If you don't do this, `fbvector` will fail to compile with a `static_assert`. -#### Additional Constraints - -Similar improvements are possible in presence of a "simple" type -- more specifically, one that has a trivial assignment (i.e. -assignment is the same as bitblitting the bits over) or a nothrow -default constructor. These traits are used gainfully by -`fbvector` in a variety of places. Fortunately, these traits are -already present in the C++ standard (well, currently in Boost). -To summarize, in order to work with `fbvector`, a type `Widget` -must pass: - - static_assert( - IsRelocatable::value && - (boost::has_trivial_assign::value || - boost::has_nothrow_constructor::value), - ""); - -These traits go hand in hand; for example, it would be very -difficult to design a class that satisfies one branch of the -conjunction above but not the other. `fbvector` uses these simple -constraints to minimize the number of copies made on many common -operations such as `push_back`, `insert`, or `resize`. - -To make it easy for you to state assumptions about a given type -or family of parameterized types, check Traits.h and in -particular handy family of macros FOLLY_ASSUME_FBVECTOR_COMPATIBLE*. - ### Miscellaneous *** diff --git a/folly/docs/Traits.md b/folly/docs/Traits.md index 18359b17..daacadbe 100644 --- a/folly/docs/Traits.md +++ b/folly/docs/Traits.md @@ -1,7 +1,7 @@ 'folly/Traits.h' ----------------- -Implements traits complementary to those provided in +Implements traits complementary to those provided in * Implements `IsRelocatable` trait. * Implements `IsOneOf` trait @@ -10,12 +10,11 @@ Implements traits complementary to those provided in ### Motivation *** -`` is the Boost type-traits library defining a -variety of traits such as `is_integral` or `is_floating_point`. This helps -to gain more information about a given type. -Many traits introduced by Boost have been standardized in C++11. +`` is the Standard type-traits library defining a variety of traits +such as `is_integral` or `is_floating_point`. This helps to gain more +information about a given type. -`folly/Traits.h` implements traits complementing those present in boost. +`folly/Traits.h` implements traits complementing those present in the Standard. ### IsRelocatable @@ -88,11 +87,11 @@ a value of type T by using memcpy. namespace folly { // defining specialization of IsRelocatable for MySimpleType template <> - struct IsRelocatable : boost::true_type {}; + struct IsRelocatable : std::true_type {}; // defining specialization of IsRelocatable for MyParameterizedType template struct IsRelocatable> - : ::boost::true_type {}; + : ::std::true_type {}; } ``` @@ -111,17 +110,6 @@ a value of type T by using memcpy. } ``` - * Stating that a type has no throw constructor using a macro - - ```Cpp - namespace boost { - // For a Regular Type - FOLLY_ASSUME_HAS_NOTHROW_CONSTRUCTOR(MySimpleType); - // For a Parameterized Type - FOLLY_ASSUME_HAS_NOTHROW_CONSTRUCTOR(MyParameterizedType); - } - ``` - `fbvector` only works with relocatable objects. If assumptions are not stated explicitly, `fbvector` or `fbvector` will fail to compile due to assertion below: @@ -157,9 +145,9 @@ Similarly, Few common types, namely `std::basic_string`, `std::vector`, `std::list`, `std::map`, `std::deque`, `std::set`, `std::unique_ptr`, `std::shared_ptr`, -`std::function`, `boost::shared_ptr` which are compatible with `fbvector` are -already instantiated and declared compatible with `fbvector`. `fbvector` can be -directly used with any of these C++ types. +`std::function`, which are compatible with `fbvector` are already instantiated +and declared compatible with `fbvector`. `fbvector` can be directly used with +any of these C++ types. `std::pair` can be safely assumed to be compatible with `fbvector` if both of its components are. @@ -167,7 +155,7 @@ its components are. ### IsOneOf *** -`boost::is_same::value` can be used to test if types of T1 and T2 are -same. `folly::IsOneOf::value` can be used to test if type of T1 +`std::is_same::value` can be used to test if types of T1 and T2 are +same. `folly::IsOneOf::value` can be used to test if type of T1 matches the type of one of the other template parameter, T1, T2, ...Tn. Recursion is used to implement this type trait. -- 2.34.1