issue#11: cds: changed __CDS_ guard prefix to CDSLIB_ for all .h files
[libcds.git] / cds / container / details / make_michael_list.h
1 //$$CDS-header$$
2
3 #ifndef CDSLIB_CONTAINER_DETAILS_MAKE_MICHAEL_LIST_H
4 #define CDSLIB_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                 template <typename... Args>
32                 node_type( Args&&... args )
33                     : m_Value( std::forward<Args>(args)... )
34                 {}
35             };
36
37             typedef Traits original_traits;
38
39             typedef typename original_traits::allocator::template rebind<node_type>::other allocator_type;
40             typedef cds::details::Allocator< node_type, allocator_type > cxx_allocator;
41
42             struct node_deallocator
43             {
44                 void operator ()( node_type * pNode )
45                 {
46                     cxx_allocator().Delete( pNode );
47                 }
48             };
49
50             typedef typename opt::details::make_comparator< value_type, original_traits >::type key_comparator;
51
52             struct value_accessor
53             {
54                 value_type const & operator()( node_type const& node ) const
55                 {
56                     return node.m_Value;
57                 }
58             };
59
60             template <typename Less>
61             struct less_wrapper {
62                 typedef cds::details::compare_wrapper< node_type, cds::opt::details::make_comparator_from_less<Less>, value_accessor > type;
63             };
64
65             struct intrusive_traits: public original_traits
66             {
67                 typedef intrusive::michael_list::base_hook< opt::gc<gc> > hook;
68                 typedef node_deallocator disposer;
69                 typedef cds::details::compare_wrapper< node_type, key_comparator, value_accessor > compare;
70                 static CDS_CONSTEXPR const opt::link_check_type link_checker = cds::intrusive::michael_list::traits::link_checker;
71             };
72
73             typedef intrusive::MichaelList<gc, node_type, intrusive_traits>  type;
74         };
75     }   // namespace details
76     //@endcond
77
78 }}  // namespace cds::container
79
80 #endif  // #ifndef CDSLIB_CONTAINER_DETAILS_MAKE_MICHAEL_LIST_H