macro for cross platform x64 detection
[folly.git] / folly / small_vector.h
index ed2c44f1ebe8cac78930b7cd10b88e7500209691..06d2a3050ec25ec9c1b340406e27bcfc117f0daf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2014 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,7 +15,8 @@
  */
 
 /*
- * For high-level documentation and usage examples see folly/doc/small_vector.md
+ * For high-level documentation and usage examples see
+ * folly/docs/small_vector.md
  *
  * @author Jordan DeLong <delong.j@fb.com>
  */
 
 #include "folly/Malloc.h"
 
-#if defined(__GNUC__) && defined(__x86_64__)
+#if defined(__GNUC__) && FOLLY_X64
 # include "folly/SmallLocks.h"
 # define FB_PACKED __attribute__((packed))
 #else
 # define FB_PACKED
 #endif
 
-#ifdef FOLLY_HAVE_MALLOC_SIZE
+#if FOLLY_HAVE_MALLOC_SIZE
   extern "C" std::size_t malloc_size(const void*);
-# ifndef FOLLY_HAVE_MALLOC_USABLE_SIZE
+# if !FOLLY_HAVE_MALLOC_USABLE_SIZE
 #  define malloc_usable_size malloc_size
 # endif
 # ifndef malloc_usable_size
@@ -116,7 +117,7 @@ namespace detail {
    */
   template<class T>
   typename std::enable_if<
-    !boost::has_trivial_copy<T>::value
+    !FOLLY_IS_TRIVIALLY_COPYABLE(T)
   >::type
   moveToUninitialized(T* first, T* last, T* out) {
     auto const count = last - first;
@@ -138,11 +139,10 @@ namespace detail {
     }
   }
 
-  // Specialization for trivially copyable types.  (TODO: change to
-  // std::is_trivially_copyable when that works.)
+  // Specialization for trivially copyable types.
   template<class T>
   typename std::enable_if<
-    boost::has_trivial_copy<T>::value
+    FOLLY_IS_TRIVIALLY_COPYABLE(T)
   >::type
   moveToUninitialized(T* first, T* last, T* out) {
     std::memmove(out, first, (last - first) * sizeof *first);
@@ -156,7 +156,7 @@ namespace detail {
    */
   template<class T>
   typename std::enable_if<
-    !boost::has_trivial_copy<T>::value
+    !FOLLY_IS_TRIVIALLY_COPYABLE(T)
   >::type
   moveObjectsRight(T* first, T* lastConstructed, T* realLast) {
     if (lastConstructed == realLast) {
@@ -195,7 +195,7 @@ namespace detail {
   // change to std::is_trivially_copyable when that works.)
   template<class T>
   typename std::enable_if<
-    boost::has_trivial_copy<T>::value
+    FOLLY_IS_TRIVIALLY_COPYABLE(T)
   >::type
   moveObjectsRight(T* first, T* lastConstructed, T* realLast) {
     std::move_backward(first, lastConstructed, realLast);
@@ -228,7 +228,7 @@ namespace detail {
     IntegralSizePolicy() : size_(0) {}
 
   protected:
-    std::size_t policyMaxSize() const {
+    static constexpr std::size_t policyMaxSize() {
       return SizeType(~kExternMask);
     }
 
@@ -268,7 +268,7 @@ namespace detail {
     SizeType size_;
   };
 
-#ifdef __x86_64__
+#if FOLLY_X64
   template<class SizeType, bool ShouldUseHeap>
   struct OneBitMutexImpl {
     typedef SizeType InternalSizeType;
@@ -282,7 +282,7 @@ namespace detail {
   protected:
     static bool const kShouldUseHeap = ShouldUseHeap;
 
-    std::size_t policyMaxSize() const {
+    static constexpr std::size_t policyMaxSize() {
       return SizeType(~(SizeType(1) << kLockBit | kExternMask));
     }
 
@@ -529,9 +529,9 @@ public:
     return std::lexicographical_compare(begin(), end(), o.begin(), o.end());
   }
 
-  size_type max_size() const {
+  static constexpr size_type max_size() {
     return !BaseType::kShouldUseHeap ? MaxInline
-                                     : this->policyMaxSize();
+                                     : BaseType::policyMaxSize();
   }
 
   size_type size()         const { return this->doSize(); }
@@ -966,7 +966,7 @@ private:
     doConstruct(n, val);
   }
 
-  void makeSize(size_type size, value_type* v = NULL) {
+  void makeSize(size_type size, value_type* v = nullptr) {
     makeSize(size, v, size - 1);
   }
 
@@ -1009,7 +1009,7 @@ private:
         detail::shiftPointer(newh, kHeapifyCapacitySize) :
         newh);
 
-    if (v != NULL) {
+    if (v != nullptr) {
       // move new element
       try {
         new (&newp[pos]) value_type(std::move(*v));
@@ -1100,7 +1100,7 @@ private:
     }
   } FB_PACKED;
 
-#if defined(__x86_64_)
+#if FOLLY_X64
   typedef unsigned char InlineStorageType[sizeof(value_type) * MaxInline];
 #else
   typedef typename std::aligned_storage<