I'm completing an online programming challenge (non-competitive) just to help me broaden my C++ skills a bit. In my case, it involves making a wrapper class of sorts for the std::set. I'm wanting to go all-out on it and make some "fashionable" constructors for it, one of which being similar to C-style array
initializations.
1 2 3 4 5 6
// C-array initialization.
int array[5] = { 1, 2, 3, 4, 5 };
// Some example usage of what I'm wanting.
Set<long> num_set = { 10, 20, 30, 40, 50 };
Set<std::string> str_set = { "Hello", "I", "am", "a", "set." };
I almost never overload operators when I work--if it can be done with a function, it's done with a function--but I realize that doesn't make the best user-experience when other people come across your code, so that's what I'm trying to improve.
It looks like I'm going to be needing to overload the = operator, no big deal. But the array segment is confusing, since {} is not an overloadable operator in C++. Anyone done this before? Any ideas or example code they know of?
Wow, incredibly simple! I wasn't aware of this being part of the standard library. It's not as customizable as an operator overload as I was expecting it to be, but it definitely does more than its fair share of the heavy lifting. Thanks JLBorges!