- lib:
boost/libs/functional/factory
- repo:
boostorg/functional
- commit:
1706cb59
, 2017-02-03
Header <boost/functional/factory.hpp>
and <boost/functional/value_factory.hpp>
enum factory_alloc_propagation {
factory_alloc_for_pointee_and_deleter, factory_passes_alloc_to_smart_pointer
};
template<typename Pointer, typename Allocator=void,
factory_alloc_propagation AP=factory_alloc_for_pointee_and_deleter>
class factory : allocator_type { // when not 'void'
public:
using result_type = remove_cv<Pointer>::type;
using value_type = boost::pointee<result_type>::type;
using allocator_type = Allocator::rebind<value_type>::other; // when not 'void'
factory(Allocator const& a = Allocator());
template<typename ...T> result_type operator()(T &... a) const {
return result_type(new value_type(a...)); // for 'Allocator' is 'void'
value_type* ptr = new (allocate(1)) value_type(a...);
return result_type(ptr,
/*deleter*/[](value_type* ptr){ ptr && ptr->~value_type(); this->deallocate(ptr, 1); },
/*allocator*/ *this); // when AP == factory_alloc_for_pointee_and_deleter
}
};
template<typename T>
class value_factory {
public:
using result_type = T;
value_factory();
template<typename ...T> result_type operator()(T &... a) const { return T(a...); }
};
- Factories wrapps object construction expressions, which are not
bind
able. factory
supportsT*
, as well as smart pointer types.factory
used withAllocator
, can be used with smart pointers likesmart_ptr
, which accepting a deleter and an allocator.
<boost/config.hpp>
<boost/get_pointer.hpp>
<boost/pointee.hpp>
<boost/type_traits/remove_cv.hpp>
<boost/preprocessor/iteration/iterate.hpp>
<boost/preprocessor/repetition/enum_params.hpp>
,<boost/preprocessor/repetition/enum_binary_params.hpp>
Language: lambda expression (C++11)