typedef std::unique_ptr< node_type, node_disposer > scoped_node_ptr;
-# ifndef CDS_CXX11_LAMBDA_SUPPORT
- struct empty_insert_functor {
- void operator()( value_type& ) const
- {}
- };
-
- struct empty_find_functor {
- template <typename Q>
- void operator()( node_type& item, Q& val ) const
- {}
- };
-
- template <typename Func>
- class insert_wrapper: protected cds::details::functor_wrapper<Func>
- {
- typedef cds::details::functor_wrapper<Func> base_class;
- public:
- insert_wrapper( Func f ): base_class(f) {}
-
- void operator()( node_type& node )
- {
- base_class::get()( node.m_val );
- }
- };
-
- template <typename Q, typename Func>
- class ensure_wrapper: protected cds::details::functor_wrapper<Func>
- {
- typedef cds::details::functor_wrapper<Func> base_class;
- public:
- Q const& val;
-
- ensure_wrapper( Q const& v, Func f) : base_class(f), val(v) {}
-
- void operator()( bool bNew, node_type& item, node_type const& )
- {
- base_class::get()( bNew, item.m_val, val );
- }
- };
-
- template <typename Func>
- class find_wrapper: protected cds::details::functor_wrapper<Func>
- {
- typedef cds::details::functor_wrapper<Func> base_class;
- public:
- find_wrapper( Func f )
- : base_class(f)
- {}
-
- template <typename Q>
- void operator()( node_type& item, Q& val )
- {
- base_class::get()( item.m_val, val );
- }
- };
-# endif
//@endcond
public:
template <typename Q>
bool insert( Q const& val )
{
-# ifdef CDS_CXX11_LAMBDA_SUPPORT
return insert( val, []( value_type& ) {} );
-# else
- return insert( val, empty_insert_functor() );
-# endif
}
/// Inserts new node
bool insert( Q const& val, Func f )
{
scoped_node_ptr pNode( alloc_node( val ));
-# ifdef CDS_CXX11_LAMBDA_SUPPORT
- if ( base_class::insert( *pNode, [&f]( node_type& node ) { cds::unref(f)( node.m_val ); } ))
-# else
- insert_wrapper<Func> wrapper( f );
- if ( base_class::insert( *pNode, cds::ref(wrapper) ))
-# endif
- {
+ if ( base_class::insert( *pNode, [&f]( node_type& node ) { cds::unref(f)( node.m_val ); } )) {
pNode.release();
return true;
}
std::pair<bool, bool> ensure( Q const& val, Func func )
{
scoped_node_ptr pNode( alloc_node( val ));
-# ifdef CDS_CXX11_LAMBDA_SUPPORT
std::pair<bool, bool> res = base_class::ensure( *pNode,
[&val,&func](bool bNew, node_type& item, node_type const& ){ cds::unref(func)( bNew, item.m_val, val ); }
);
-# else
- ensure_wrapper<Q, Func> wrapper( val, func );
- std::pair<bool, bool> res = base_class::ensure( *pNode, cds::ref(wrapper) );
-# endif
if ( res.first && res.second )
pNode.release();
return res;
template <typename Q, typename Func>
bool find( Q& val, Func f )
{
-# ifdef CDS_CXX11_LAMBDA_SUPPORT
return base_class::find( val, [&f](node_type& item, Q& v) { cds::unref(f)( item.m_val, v );});
-# else
- find_wrapper<Func> wrapper(f);
- return base_class::find( val, cds::ref(wrapper) );
-# endif
}
/// Find the key \p val using \p pred predicate for comparing
template <typename Q, typename Predicate, typename Func>
bool find_with( Q& val, Predicate pred, Func f )
{
-# ifdef CDS_CXX11_LAMBDA_SUPPORT
return base_class::find_with( val, typename maker::template predicate_wrapper<Predicate, bool>(),
[&f](node_type& item, Q& v) { cds::unref(f)( item.m_val, v );});
-# else
- find_wrapper<Func> wrapper(f);
- return base_class::find_with( val, typename maker::template predicate_wrapper<Predicate, bool>(), cds::ref(wrapper) );
-# endif
}
/// Find the key \p val
template <typename Q, typename Func>
bool find( Q const& val, Func f )
{
-# ifdef CDS_CXX11_LAMBDA_SUPPORT
return base_class::find( val, [&f](node_type& item, Q const& v) { cds::unref(f)( item.m_val, v );});
-# else
- find_wrapper<Func> wrapper(f);
- return base_class::find( val, cds::ref(wrapper) );
-# endif
}
/// Find the key \p val using \p pred predicate for comparing
template <typename Q, typename Predicate, typename Func>
bool find_with( Q const& val, Predicate pred, Func f )
{
-# ifdef CDS_CXX11_LAMBDA_SUPPORT
return base_class::find_with( val, typename maker::template predicate_wrapper<Predicate, bool>(),
[&f](node_type& item, Q const& v) { cds::unref(f)( item.m_val, v );});
-# else
- find_wrapper<Func> wrapper(f);
- return base_class::find_with( val, typename maker::template predicate_wrapper<Predicate, bool>(), cds::ref(wrapper) );
-# endif
}
/// Find the key \p val
template <typename Q>
bool find( Q const& val )
{
-# ifdef CDS_CXX11_LAMBDA_SUPPORT
return base_class::find( val, [](node_type&, Q const&) {});
-# else
- return base_class::find( val, empty_find_functor());
-# endif
}
/// Find the key \p val using \p pred predicate for comparing
template <typename Q, typename Predicate>
bool find_with( Q const& val, Predicate pred )
{
-# ifdef CDS_CXX11_LAMBDA_SUPPORT
return base_class::find_with( val, typename maker::template predicate_wrapper<Predicate, bool>(), [](node_type&, Q const&) {});
-# else
- return base_class::find_with( val, typename maker::template predicate_wrapper<Predicate, bool>(), empty_find_functor());
-# endif
}
/// Clears the set