forked from boostorg/range
Allow iterator copy for lambda in transformed and filtered
Lambda has no default constructor nor a copy or move assignment. range\test\adaptors.cpp is checking that produced ranges are copiable, but it is not doing so the for lambda, or lambda like objects. default_constructible_unary_fn uses an optional for default construction. I extended it to use its emplace facility to copy assign non copy assignable types. (see boost::optional 'Type Requierment': 'If T is not MoveAssignable, it is still possible to reset the value of optional<T> using function emplace():')
This commit is contained in:
@@ -32,6 +32,23 @@ public:
|
||||
: m_impl(source)
|
||||
{
|
||||
}
|
||||
default_constructible_unary_fn_wrapper(const default_constructible_unary_fn_wrapper& source)
|
||||
: m_impl(source.m_impl)
|
||||
{
|
||||
}
|
||||
default_constructible_unary_fn_wrapper& operator=(const default_constructible_unary_fn_wrapper& source)
|
||||
{
|
||||
if (source.m_impl)
|
||||
{
|
||||
// Lambda are not copy/move assignable.
|
||||
m_impl.emplace(*source.m_impl);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_impl.reset();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
template<typename Arg>
|
||||
R operator()(const Arg& arg) const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user