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
版权声明:本文标题:c++ - Should a constructor with a std::initializer_list be explicit? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736304995a1932432.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论