I'm writing an iterator facade, but it seems like my iterator will violate even basic Iterator
concept. The problem is that the iterator accepts any Callable
, which might render fundamental operations on Regular Types ill formed. I'm following definition presented by Alexander Stepanov. Here is the declaration:
template<typename Callable, typename Iterator>
class transform_iterator
Question: How to wrap callable to make it regular type?
Actually I need wrapper only to be:
Copy constructible
Copy assignable
Destructible
and not Regular Type in general.
My first attempt: wrap into std::optional<>
:
template <typename T>
class regular_box
{
std::experimental::optional<T> value;
public:
//constructors, operator=
template <typename ... ArgTypes>
auto operator()(ArgTypes&& ... args)
{
return callable.value()(std::forward<ArgTypes>(args)...);
}
};
But it doesn't solve the problem with assignment, since if Callable
is not copy assignable, the regular_box
will not be copy assignable as well.
Plan B: std::function<>
. Though I would like to postpone it for as long as possible.
I could make multiple levels of fallbacks, but I couldn't find any better solution than that.