I guess if you want a custom initializer list, the following should suffice?
template <typename T>
class Initializer
{
private:
T* _List;
size_t len;
public:
Initializer()
: _List(nullptr), len(0) {}
template <typename... _Rest>
Initializer(T _first, _Rest... _rest)
: _List(new T[sizeof...(_rest) + 1]{_first, _rest...}),
len(sizeof...(_rest) + 1) {}
Initializer<T>& operator=(Initializer<T> &&) = delete; // move operator [Implement your own if you want.]
Initializer<T>& operator=(const Initializer<T>& ) = delete; // copy operator [Implement your own if you want.]
const T operator[] (size_t index) const noexcept
{ return _List[index]; }
T& operator[] (size_t index) noexcept
{ return _List[index]; }
const T* begin() const noexcept
{ return _List; }
T* begin() noexcept
{ return _List; }
const T* end() const noexcept
{ return &_List[len]; }
T* end() noexcept
{ return &_List[len]; }
size_t length() const noexcept
{ return len; }
~Initializer() noexcept
{ _List != nullptr ? delete[] _List : void(0); }
};
Examples:
Passing it as a function constructor:
void func(Initializer<int> list)
{
// Nothing. Absolutely nothing...
}
int main()
{
func({ 104, 101, 108, 108, 111}); // Don't translate to ASCII ;)
}
Initializing it normally:
Initializer<const char*> AListOfStrings = {
"This is a test",
"Mic testing 123",
"Oh good it works!"
};
Now I don't know if there are any edge cases to this way, but if there are you could perhaps let me know about it in the comments and i could try to fix it.
Anyway I think this should be ok.