Inserting byte array using operators
I was wondering if something like this is possible using class operators:
ByteClass bc;
bc += {0x00, 0x00};
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <algorithm>
#include <initializer_list>
#include <iostream>
#include <vector>
template <typename T, typename Allocator = std::allocator<T>>
class my_vector : public std::vector<T, Allocator>
{
public:
my_vector& operator += (std::initializer_list<T> il)
{
insert(end(), std::move(il));
return *this;
}
};
int main()
{
my_vector<int> container;
container += {0x00, 0x00};
for (auto element : container)
std::cout << element << ' ';
std::cout << '\n';
}
|
Topic archived. No new replies allowed.