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 opt::details::make_comparator< key_type, original_type_traits >::type key_comparator;
68 template <typename Less>
70 typedef cds::details::compare_wrapper< node_type, cds::opt::details::make_comparator_from_less<Less>, key_field_accessor > type;
73 struct intrusive_traits: public original_type_traits
75 typedef intrusive::lazy_list::base_hook< opt::gc<gc> > hook;
76 typedef node_deallocator disposer;
77 typedef cds::details::compare_wrapper< node_type, key_comparator, key_field_accessor > compare;
78 static const opt::link_check_type link_checker = cds::intrusive::lazy_list::traits::link_checker;
81 typedef intrusive::LazyList<gc, node_type, intrusive_traits> type;
83 } // namespace details
86 }} // namespace cds::container
88 #endif // #ifndef CDSLIB_CONTAINER_DETAILS_MAKE_LAZY_KVLIST_H