3 #ifndef CDSLIB_CONTAINER_DETAILS_MAKE_LAZY_KVLIST_H
4 #define CDSLIB_CONTAINER_DETAILS_MAKE_LAZY_KVLIST_H
6 #include <cds/details/binary_functor_wrapper.h>
8 namespace cds { namespace container {
13 template <class GC, typename K, typename T, class Traits>
14 struct make_lazy_kvlist
16 typedef Traits original_type_traits;
20 typedef T mapped_type;
21 typedef std::pair<key_type const, mapped_type> value_type;
23 struct node_type: public intrusive::lazy_list::node<gc, typename original_type_traits::lock_type>
28 node_type( Q const& key )
29 : m_Data( key, mapped_type() )
32 template <typename Q, typename R>
33 explicit node_type( std::pair<Q, R> const& pair )
37 template <typename Q, typename R>
38 node_type( Q const& key, R const& value )
39 : m_Data( key, value )
42 template <typename Ky, typename... Args>
43 node_type( Ky&& key, Args&&... args )
44 : m_Data( std::forward<Ky>( key ), std::move( mapped_type( std::forward<Args>( args )... ) ) )
48 typedef typename original_type_traits::allocator::template rebind<node_type>::other allocator_type;
49 typedef cds::details::Allocator< node_type, allocator_type > cxx_allocator;
51 struct node_deallocator
53 void operator ()( node_type * pNode )
55 cxx_allocator().Delete( pNode );
59 struct key_field_accessor {
60 key_type const& operator()( node_type const& pair )
62 return pair.m_Data.first;
66 typedef typename std::conditional< original_type_traits::sort,
67 typename opt::details::make_comparator< value_type, original_type_traits >::type,
68 typename opt::details::make_equal_to< value_type, original_type_traits >::type
69 >::type key_comparator;
72 template <typename Less>
74 typedef cds::details::compare_wrapper< node_type, cds::opt::details::make_comparator_from_less<Less>, key_field_accessor > type;
77 template <typename Equal>
78 struct equal_to_wrapper {
79 typedef cds::details::predicate_wrapper< node_type, Equal, key_field_accessor > type;
82 struct intrusive_traits: public original_type_traits
84 typedef intrusive::lazy_list::base_hook< opt::gc<gc> > hook;
85 typedef node_deallocator disposer;
87 typedef typename std::conditional< std::is_same< typename original_type_traits::equal_to, cds::opt::none >::value,
89 typename equal_to_wrapper< typename original_type_traits::equal_to >::type
92 typedef typename std::conditional< original_type_traits::sort,
93 cds::details::compare_wrapper< node_type, key_comparator, key_field_accessor >,
97 static const opt::link_check_type link_checker = cds::intrusive::lazy_list::traits::link_checker;
100 typedef intrusive::LazyList<gc, node_type, intrusive_traits> type;
102 } // namespace details
105 }} // namespace cds::container
107 #endif // #ifndef CDSLIB_CONTAINER_DETAILS_MAKE_LAZY_KVLIST_H