Copyright 2012 -> 2013
[folly.git] / folly / small_vector.h
index 0a75d3ad2ea545ed4673139742cce1f34ddb30e9..065cfae4eaff19b31c8102b6414f9f53445f65ca 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2013 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -100,7 +100,7 @@ struct OneBitMutex;
 //////////////////////////////////////////////////////////////////////
 
 template<class T, std::size_t M, class A, class B, class C>
-struct small_vector;
+class small_vector;
 
 //////////////////////////////////////////////////////////////////////
 
@@ -205,7 +205,7 @@ namespace detail {
   void populateMemForward(T* mem, std::size_t n, Function const& op) {
     std::size_t idx = 0;
     try {
-      for (int i = 0; i < n; ++i) {
+      for (size_t i = 0; i < n; ++i) {
         op(&mem[idx]);
         ++idx;
       }
@@ -414,7 +414,8 @@ namespace detail {
   }
   template <class T>
   T* pointerFlagClear(T* p) {
-    return reinterpret_cast<T*>(reinterpret_cast<uintptr_t>(p) & ~1);
+    return reinterpret_cast<T*>(
+      reinterpret_cast<uintptr_t>(p) & ~uintptr_t(1));
   }
   inline void* shiftPointer(void* p, size_t sizeBytes) {
     return static_cast<char*>(p) + sizeBytes;
@@ -846,14 +847,14 @@ public:
 
   reference at(size_type i) {
     if (i >= size()) {
-      throw std::out_of_range();
+      throw std::out_of_range("index out of range");
     }
     return (*this)[i];
   }
 
   const_reference at(size_type i) const {
     if (i >= size()) {
-      throw std::out_of_range();
+      throw std::out_of_range("index out of range");
     }
     return (*this)[i];
   }
@@ -994,10 +995,7 @@ private:
       needBytes += kHeapifyCapacitySize;
     }
     auto const sizeBytes = goodMallocSize(needBytes);
-    void* newh = std::malloc(sizeBytes);
-    if (!newh) {
-      throw std::bad_alloc();
-    }
+    void* newh = checkedMalloc(sizeBytes);
     // We expect newh to be at least 2-aligned, because we want to
     // use its least significant bit as a flag.
     assert(!detail::pointerFlagGet(newh));