Move libcds 1.6.0 from SVN
[libcds.git] / cds / container / details / make_lazy_list.h
1 //$$CDS-header$$
2
3 #ifndef __CDS_CONTAINER_DETAILS_MAKE_LAZY_LIST_H
4 #define __CDS_CONTAINER_DETAILS_MAKE_LAZY_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_lazy_list
15         {
16             typedef GC      gc;
17             typedef T       value_type;
18             typedef Traits original_type_traits;
19
20             struct node_type : public intrusive::lazy_list::node<gc, typename original_type_traits::lock_type>
21             {
22                 value_type  m_Value;
23
24                 node_type()
25                 {}
26
27                 template <typename Q>
28                 node_type( Q const& v )
29                     : m_Value(v)
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 typename original_type_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_type_traits >::type key_comparator;
51
52             struct value_accessor {
53                 value_type const & operator()( node_type const & node ) const
54                 {
55                     return node.m_Value;
56                 }
57             };
58
59             template <typename Less>
60             struct less_wrapper {
61                 typedef cds::details::compare_wrapper< node_type, cds::opt::details::make_comparator_from_less<Less>, value_accessor > type;
62             };
63
64             struct type_traits: public original_type_traits
65             {
66                 typedef intrusive::lazy_list::base_hook< opt::gc<gc> >  hook;
67                 typedef node_deallocator               disposer;
68
69                 typedef cds::details::compare_wrapper< node_type, key_comparator, value_accessor > compare;
70             };
71
72             typedef intrusive::LazyList<gc, node_type, type_traits>  type;
73         };
74     }   // namespace details
75     //@endcond
76
77 }}  // namespace cds::container
78
79 #endif  // #ifndef __CDS_CONTAINER_DETAILS_MAKE_MICHAEL_LIST_H