std::make_unique
을 사용하여 생성자가 std::initializer_list
인 클래스를 인스턴스화하려고합니다. 여기에 최소한의 경우 :make_unique/make_shared를 통해 initializer_list 생성자를 호출합니다.
#include <string>
#include <vector>
#include <initializer_list>
#include <memory>
struct Foo {
Foo(std::initializer_list<std::string> strings) : strings(strings) {}
std::vector<std::string> strings;
};
int main(int, char**) {
auto ptr = std::make_unique<Foo>({"Hello", "World"});
return 0;
}
당신은 그것을 구축하지 않는 Coliru에 볼 수 있습니다
main.cpp:14:56: error: no matching function for call to 'make_unique(<brace-enclosed initializer list>)'
auto ptr = std::make_unique<Foo>({"Hello", "World"});
그래서, initializer_list
의를 사용하여 보도 할 수없는 make_unique
입니까? GCC 4.9.1에 버그가 있습니까? 또는 나는 무엇인가 간과 했느냐?
중괄호 목록은 템플릿 인수 공제로 추론 할 수 없습니다. 'make_unique (std :: initializer_list ({ "Hello", "World"}))'를 시도해보십시오. –
@KerrekSB 글쎄, 그건 내 대답처럼 보입니다 :) – Quentin
흠, 작동합니까, 그리고 도움이됩니까? –