You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the size is 1, we can use std::exchange to efficiently move the values. If the size is constant, we could use a circular buffer on stack (eg: with a backend on std::array instead of std::vector)
If the circular buffer implementation supports a std::exchange like operation, queue_.front() and queue_.push_back could be made one single operation
If the drop_last was templated instead of onReceive, there would be no need of using std::any
Big issue: SOMEHOW_FORWARD_OR_MOVE
The text was updated successfully, but these errors were encountered:
Doesn't this implementation assume that all the (tuples of) values coming successively to the pipe are of the same type?
Yes, but I feel that this is a "reasonably" safe (and in case of input coming from containers, guaranteed) assumption (what's a few throws among friends)
Perhaps, this limitation can be made explicit by templating the class itself (and thus removing the need for std::any)
Or else, it'd need tuple + lambda shenanigans to do it:
// the template parttemplate <classT, class... V>
structexchange_result {
T old;
std::tuple<V...> tuple;
};
template <classValue, classV0, class...V>
autotuple_exchange(std::tuple<V0, V...>&& existing, Value&& in) {
auto a = std::move(std::get<0>(existing));
return exchange_result{a,
std::make_tuple<V..., Value>(std::move(std::get<V>(existing))..., in)};
}
I am not sure if what I wish to do with lambda is legal (or possible), but essentially, I wanted to use onReceive to store a lambda in a std::function. The lambda acts the storage for the tuple and the queue logic, while returning a new lambda for the onReceive function to store (and delete the original).
EDIT:
If we force the interface to have a constant type (or std::any) we can have really nice interface
If a pipe is allowed to store the values locally in a circular queue, it can accumulate the first N values in it, and then release the rest.
Assuming an interface like Boost.CircularBuffer for the circular queue
Can it be made more efficient?
std::exchange
to efficiently move the values. If the size is constant, we could use a circular buffer on stack (eg: with a backend onstd::array
instead ofstd::vector
)std::exchange
like operation,queue_.front()
andqueue_.push_back
could be made one single operationdrop_last
was templated instead ofonReceive
, there would be no need of usingstd::any
Big issue: SOMEHOW_FORWARD_OR_MOVE
The text was updated successfully, but these errors were encountered: