I'm trying to use std::make_unique
to instanciate a class whose constructor is to receive an std::initializer_list
. Here a minimal case :
#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;
}
You can see on Coliru that it doesn't build :
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"});
So, is make_unique
reportedly unable to use initializer_list
s ? Is there a bug in GCC 4.9.1 ? Or did I overlook something ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…