From 5c7e02423ef6fa619d8e73a30f63a3332b9913e2 Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Wed, 17 Aug 2016 08:33:12 -0700 Subject: [PATCH] Move the type_traits portability header into its own portability header Summary: Split up the big, all-inclusive Portability header a bit Reviewed By: yfeldblum Differential Revision: D3723253 fbshipit-source-id: a91c38775825626f3c13853ac8168daa078a169a --- folly/Makefile.am | 1 + folly/Portability.h | 22 ---------------- folly/experimental/LockFreeRingBuffer.h | 3 ++- folly/portability/TypeTraits.h | 35 +++++++++++++++++++++++++ folly/small_vector.h | 1 + folly/test/small_vector_test.cpp | 1 + 6 files changed, 40 insertions(+), 23 deletions(-) create mode 100644 folly/portability/TypeTraits.h diff --git a/folly/Makefile.am b/folly/Makefile.am index b9d5424a..0691344b 100644 --- a/folly/Makefile.am +++ b/folly/Makefile.am @@ -296,6 +296,7 @@ nobase_follyinclude_HEADERS = \ portability/SysTypes.h \ portability/SysUio.h \ portability/Time.h \ + portability/TypeTraits.h \ portability/Windows.h \ portability/Unistd.h \ Preprocessor.h \ diff --git a/folly/Portability.h b/folly/Portability.h index e6d06a4d..a780eedc 100644 --- a/folly/Portability.h +++ b/folly/Portability.h @@ -245,28 +245,6 @@ namespace std { typedef ::max_align_t max_align_t; } #include #endif -#if defined(__cplusplus) -// Unfortunately, boost::has_trivial_copy is broken in libc++ due to its -// usage of __has_trivial_copy(), so we can't use it as a -// least-common-denominator for C++11 implementations that don't support -// std::is_trivially_copyable. -// -// http://stackoverflow.com/questions/12754886/has-trivial-copy-behaves-differently-in-clang-and-gcc-whos-right -// -// As a result, use std::is_trivially_copyable() where it exists, and fall back -// to Boost otherwise. -#if FOLLY_HAVE_STD__IS_TRIVIALLY_COPYABLE -#include -#define FOLLY_IS_TRIVIALLY_COPYABLE(T) \ - (std::is_trivially_copyable::value) -#else -#include -#define FOLLY_IS_TRIVIALLY_COPYABLE(T) \ - (boost::has_trivial_copy::value && \ - boost::has_trivial_destructor::value) -#endif -#endif // __cplusplus - // MSVC specific defines // mainly for posix compat #ifdef _MSC_VER diff --git a/folly/experimental/LockFreeRingBuffer.h b/folly/experimental/LockFreeRingBuffer.h index 5ca4a7d2..1a2bc464 100644 --- a/folly/experimental/LockFreeRingBuffer.h +++ b/folly/experimental/LockFreeRingBuffer.h @@ -24,8 +24,9 @@ #include #include -#include #include +#include +#include #include namespace folly { diff --git a/folly/portability/TypeTraits.h b/folly/portability/TypeTraits.h new file mode 100644 index 00000000..4ff82b16 --- /dev/null +++ b/folly/portability/TypeTraits.h @@ -0,0 +1,35 @@ +/* + * Copyright 2016 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 + +// Unfortunately, boost::has_trivial_copy is broken in libc++ due to its +// usage of __has_trivial_copy(), so we can't use it as a +// least-common-denominator for C++11 implementations that don't support +// std::is_trivially_copyable. +// +// http://stackoverflow.com/questions/12754886/has-trivial-copy-behaves-differently-in-clang-and-gcc-whos-right +// +// As a result, use std::is_trivially_copyable() where it exists, and fall back +// to Boost otherwise. +#if FOLLY_HAVE_STD__IS_TRIVIALLY_COPYABLE +#include +#define FOLLY_IS_TRIVIALLY_COPYABLE(T) (std::is_trivially_copyable::value) +#else +#include +#define FOLLY_IS_TRIVIALLY_COPYABLE(T) \ + (boost::has_trivial_copy::value && boost::has_trivial_destructor::value) +#endif diff --git a/folly/small_vector.h b/folly/small_vector.h index da4547b4..3da912d2 100644 --- a/folly/small_vector.h +++ b/folly/small_vector.h @@ -49,6 +49,7 @@ #include #include #include +#include // Ignore shadowing warnings within this file, so includers can use -Wshadow. #pragma GCC diagnostic push diff --git a/folly/test/small_vector_test.cpp b/folly/test/small_vector_test.cpp index 86f24fce..7e8c92db 100644 --- a/folly/test/small_vector_test.cpp +++ b/folly/test/small_vector_test.cpp @@ -28,6 +28,7 @@ #include #include +#include using folly::small_vector; using namespace folly::small_vector_policy; -- 2.34.1