Move libcds 1.6.0 from SVN
[libcds.git] / cds / container / details / make_michael_list.h
1 //$$CDS-header$$
2
3 #ifndef __CDS_CONTAINER_DETAILS_MAKE_MICHAEL_LIST_H
4 #define __CDS_CONTAINER_DETAILS_MAKE_MICHAEL_LIST_H
5
6 #include <cds/details/binary_functor_wrapper.h>
7
8 namespace cds { namespace container {
9
10     //@cond
11     namespace details {
12
13         template <class GC, typename T, class Traits>
14         struct make_michael_list
15         {
16             typedef GC      gc;
17             typedef T       value_type;
18
19             struct node_type : public intrusive::michael_list::node<gc>
20             {
21                 value_type  m_Value;
22
23                 node_type()
24                 {}
25
26                 template <typename Q>
27                 node_type( Q const& v )
28                     : m_Value(v)
29                 {}
30
31 #       ifdef CDS_EMPLACE_SUPPORT
32                 template <typename... Args>
33                 node_type( Args&&... args )
34                     : m_Value( std::forward<Args>(args)... )
35                 {}
36 #       endif
37             };
38
39             typedef Traits original_type_traits;
40
41             typedef typename original_type_traits::allocator::template rebind<node_type>::other  allocator_type;
42             typedef cds::details::Allocator< node_type, allocator_type >                cxx_allocator;
43
44             struct node_deallocator
45             {
46                 void operator ()( node_type * pNode )
47                 {
48                     cxx_allocator().Delete( pNode );
49                 }
50             };
51
52             typedef typename opt::details::make_comparator< value_type, original_type_traits >::type key_comparator;
53
54             struct value_accessor
55             {
56                 value_type const & operator()( node_type const& node ) const
57                 {
58                     return node.m_Value;
59                 }
60             };
61
62             template <typename Less>
63             struct less_wrapper {
64                 typedef cds::details::compare_wrapper< node_type, cds::opt::details::make_comparator_from_less<Less>, value_accessor >    type;
65             };
66
67             struct type_traits: public original_type_traits
68             {
69                 typedef intrusive::michael_list::base_hook< opt::gc<gc> >  hook;
70                 typedef node_deallocator               disposer;
71
72                 typedef cds::details::compare_wrapper< node_type, key_comparator, value_accessor > compare;
73             };
74
75             typedef intrusive::MichaelList<gc, node_type, type_traits>  type;
76         };
77     }   // namespace details
78     //@endcond
79
80 }}  // namespace cds::container
81
82 #endif  // #ifndef __CDS_CONTAINER_DETAILS_MAKE_MICHAEL_LIST_H