Construct container with initializer list of iterators

吃可爱长大的小学妹 提交于 2019-12-05 05:07:04

From §13.3.2/1 ([over.match.list])

When objects of non-aggregate class type T are list-initialized (8.5.4), overload resolution selects the constructor in two phases:

— Initially, the candidate functions are the initializer-list constructors (8.5.4) of the class T and the argument list consists of the initializer list as a single argument.

— If no viable initializer-list constructor is found, overload resolution is performed again, where the candidate functions are all the constructors of the class T and the argument list consists of the elements of the initializer list.

In your case the initializer list constructor is deemed non-viable (because std::istream_iterator<std::string> is not convertible to std::string), and the second condition applies. This results in the constructor taking 2 iterators to be selected.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!