Merge branch 'integration' into dev
[libcds.git] / cds / details / allocator.h
index 9936cdac21db00a142b42142b91ed3f759af7fb4..babe8344744c5a4df9cf685ed43194e3f81941d9 100644 (file)
@@ -1,20 +1,40 @@
-//$$CDS-header$$
-
-#ifndef __CDS_DETAILS_ALLOCATOR_H
-#define __CDS_DETAILS_ALLOCATOR_H
-
 /*
-    Allocator class for the library. Supports allocating and constructing of objects
-
-    Editions:
-        2008.03.08    Maxim.Khiszinsky    Created
+    This file is a part of libcds - Concurrent Data Structures library
+
+    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
+
+    Source code repo: http://github.com/khizmax/libcds/
+    Download: http://sourceforge.net/projects/libcds/files/
+    
+    Redistribution and use in source and binary forms, with or without
+    modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice, this
+      list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+      this list of conditions and the following disclaimer in the documentation
+      and/or other materials provided with the distribution.
+
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     
 */
 
+#ifndef CDSLIB_DETAILS_ALLOCATOR_H
+#define CDSLIB_DETAILS_ALLOCATOR_H
+
 #include <type_traits>
 #include <memory>
 #include <cds/details/defs.h>
 #include <cds/user_setup/allocator.h>
-#include <boost/type_traits/has_trivial_destructor.hpp>
 
 namespace cds {
     namespace details {
@@ -40,6 +60,9 @@ namespace cds {
                 , typename Alloc::template rebind<T>::other
             >::type allocator_type;
 
+            /// \p true if underlined allocator is \p std::allocator, \p false otherwise
+            static CDS_CONSTEXPR bool const c_bStdAllocator = std::is_same< allocator_type, std::allocator<T>>::value;
+
             /// Element type
             typedef T   value_type;
 
@@ -127,14 +150,16 @@ namespace cds {
             template <typename... S>
             value_type * Construct( void * p, S const&... src )
             {
-                return new( p ) value_type( src... );
+                value_type * pv = new( p ) value_type( src... );
+                return pv;
             }
 
             /// Analogue of placement <tt>operator new( p ) T( std::forward<Args>(args)... )</tt>
             template <typename... Args>
             value_type * MoveConstruct( void * p, Args&&... args )
             {
-                return new( p ) value_type( std::forward<Args>(args)... );
+                value_type * pv = new( p ) value_type( std::forward<Args>(args)... );
+                return pv;
             }
 
             /// Rebinds allocator to other type \p Q instead of \p T
@@ -156,31 +181,6 @@ namespace cds {
             //@endcond
         };
 
-        //@cond
-        namespace {
-            template <class T>
-            static inline void impl_call_dtor(T* p, boost::false_type const&)
-            {
-                p->T::~T();
-            }
-
-            template <class T>
-            static inline void impl_call_dtor(T* p, boost::true_type const&)
-            {}
-        }
-        //@endcond
-
-        /// Helper function to call destructor of type T
-        /**
-            This function is empty for the type T that has trivial destructor.
-        */
-        template <class T>
-        static inline void call_dtor( T* p )
-        {
-            impl_call_dtor( p, ::boost::has_trivial_destructor<T>() );
-        }
-
-
         /// Deferral removing of the object of type \p T. Helper class
         template <typename T, typename Alloc = CDS_DEFAULT_ALLOCATOR>
         struct deferral_deleter {
@@ -196,7 +196,7 @@ namespace cds {
             */
             static void free( T * p )
             {
-                Allocator<T, Alloc> a;
+                Allocator<type, allocator_type> a;
                 a.Delete( p );
             }
         };
@@ -204,4 +204,4 @@ namespace cds {
     }    // namespace details
 }    // namespace cds
 
-#endif    // #ifndef __CDS_DETAILS_ALLOCATOR_H
+#endif    // #ifndef CDSLIB_DETAILS_ALLOCATOR_H