I am acquiring data from a microcontroller via UDP. Each packet is a hex string, and I need to split it into equal-sized chunks to do some processing afterwards. However, since the packets are relatively large (about 700 chars each), the time it takes to split one into chunks is larger than the time between packet arrival. This introduces latency and half of the data is lost. I cannot use TCP/IP, because the system needs to operate in real time. How can I multiprocess the following line (can it even be done):

```
list_of_chunks = [packet[i:i+n] for i in range(0, len(packet), 16)]

```
['https://Stackoverflow.com/questions/45374668', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8382085/']
You can check whether the callable is convertible to `std::function<T(T)>`:

```
template<class T, class F>
std::enable_if_t<std::is_convertible<F, std::function<T(T)>>::value, T>
f(T v, F fn) {
    return fn(v);
}

```
Make deducible blocks the compiler from trying tomdeduce that argument. Which seems like a poor choice of name; that is usually called `block_deduction` or something.

The easiest way to include the signature is a comment:

```
template <class T, class F /*T(T) signature*/>
T f(T val, F fc)
{ return fc(val); }

```

wherever you want it.

If we want compiler enforcing, we can block deduction and type erase like you did in your question. Another choice:

```
template<class Sig, class F, class=void>
struct can_call:std::false_type{};
template<class R, class...Args, class F>
struct can_call<R(Args...),F,std::enable_if_t<
  std::is_convertible<std::result_of_t<F(Args...)>,R>{}
>>:std::true_type{};
template<class...Args, class F>
struct can_call<void(Args...),F,std::void_t<
  std::result_of_t<F(Args...)>,R>{}
>>:std::true_type{};

```

that defines `can_call<Sig, F>` which is true if and only if you can call F in a context compatible with `Sig`.

```
template <class T, class F /*T(T) signature*/>
std::enable_if_t<can_call<T(T),F&>{}, T> T f(T val, F fc)
{ return fc(val); }

```

and now `F` is checked at overload resolution time to ensure it is compatible.

I used some C++14 and C++17 `std::void_t`. `void_t` is easy to write in C++11, and easy to find on SO.

There may be typos; on phone.