I am developing an app to send and receive packets.
I am working with the std::vector
class (first I started making the packets in arrays and I am open to change the method if you suggest one better).
I found this smart function to add any const char*
to a vector
object. But I would like to do another one to add them between {.. , ..}
like I can do in C#. Here an example:
vector<char*> packet;
char dest[] = { 0x10, 0x10, 0x0, 0x61 };
AppendLiteral(packet, dest); //Ok
/*Or directly:*/ AppendLiteral(packet, { 10, 10, 0, 20 }); //But this does not work
Is it possible in c++? I know in C# you can do something like this.
Edit:
A possible solution is:
vector<uint8> telegram;
vector<uint8> src = { 0x10, 0x10, 0x0, 0x20 };
vector<uint8> dst = { 0x10, 0x10, 0x0, 0x60 };
telegram.insert(telegram.end(), dst.begin(), dst.end());
telegram.insert(telegram.end(), src.begin(), src.end());
With a little function to write less:
template <typename T>
void Append(vector<T> *data, vector<T> *data2)
{
data->insert(data->end(), data2->begin(), data2->end());
}