2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef CDSLIB_OPT_ITEM_DISPOSER_H
32 #define CDSLIB_OPT_ITEM_DISPOSER_H
34 #include <cds/details/defs.h>
36 namespace cds { namespace opt {
38 /// [type-option] value cleaning
40 The cleaner is a functor called when an item is removed from a container.
41 Note, the cleaner should not delete (deallocate) the value \p val passed in.
42 However, if the \p value_type type is a structure that contains dynamically allocated
43 field(s), the cleaning functor may deallocate it and initialize to default value (usually, \p nullptr).
45 The interface for type \p value_type is:
48 void operator ()( value_type& val )
51 // code to cleanup val
56 Predefined option types:
57 \li opt::v::empty_cleaner
58 \li opt::v::destruct_cleaner
59 \li opt::v::auto_cleaner
61 template <typename Type>
62 struct value_cleaner {
64 template <typename BASE> struct pack: public BASE
66 typedef Type value_cleaner;
75 One of available type for \p opt::value_cleaner option.
76 This cleaner is empty, i.e. it does not do any cleaning.
82 void operator()( T& /*val*/ )
87 /// Cleaner that calls destructor of type \p T
89 One of available type for \p opt::value_cleaner option.
91 struct destruct_cleaner
95 void operator()( T& val )
102 /// Cleaner that calls \p T destructor if it is not trivial
104 If \p T has non-trivial destructor (<tt> std::is_trivially_destructible<T>::value </tt> is \p false),
105 the cleaner calls \p T destructor.
107 If <tt> std::is_trivially_destructible<T>::value </tt> is \p true, the cleaner is empty - no
108 destructor of \p T is called.
113 template <typename T>
114 typename std::enable_if< std::is_trivially_destructible<T>::value >::type
115 operator()( T& /*val*/ )
118 template <typename T>
119 typename std::enable_if< !std::is_trivially_destructible<T>::value >::type
128 }} // namespace cds::opt
130 #endif // #ifndef CDSLIB_OPT_ITEM_DISPOSER_H