vendredi 27 mars 2015

C++11 is it possible to construct an std::initializer_list?

I have a class that's using an std::discrete_distribution which can take an std::initializer_list OR a couple of iterators. My class is in some ways wrapping the discrete_distribution so I really wanted to mimic the ability to take an std::initializer_list which would then be passed down.


This is simple.


However, the std::initializer_list will always be constructed through some unknown values. So, if it was just a std::discrete_distribution I would just construct from iterators of some container. However, for me to make that available via my class, I would need to templatize the class for the Iterator type.


I don't want to template my class because it's only occasionally that it would use the initializer_list, and the cases where it doesn't, it uses an std::uniform_distribution_list which would make this template argument, maybe confusing.


I know I can default the template argument, and I know that I could just define only vector::iterators if I wanted; I'd just rather not.


Aucun commentaire:

Enregistrer un commentaire