admin管理员组

文章数量:1122846

I am designing a container (yeah, do not reinvent the wheel, I know). Let's call it Container<T>.

I have a constructor to allow the initial number of elements:

explicit Container(std::size_t size);

And I want to implement an initializer_list constructor:

Container(std::initializer_list<T> param);

I know the rule of having every one parameter constructors marked as explicit, but then, since the std::initializer_list could be one element, it should be marked as explicit too.

Another point of problem is what will happen with a Container<std::size_t> and

Container<std::size_t> c{4UL};

And what about deduction guides? So, what is the best practice or standard accepted way of dealing with explicit when std::initializer_list, and explicit conversion constructors and/or deduction guides are involved? NOTE: By the best way/standard way I mean the way that is more used by the industry and/or recommended by static checkers, or ISO C++ standard.

本文标签: cShould a constructor with a stdinitializerlist be explicitStack Overflow