I have such a utility class:
struct Atreturn
{
std::function<void()> funcdestr;
Atreturn( std::function<void()> fd ): funcdestr(fd) {}
~Atreturn() { funcdestr(); }
};
Note no explicit attribute at constructor.
Possible use should be:
Direct-initializing constructor call:
Atreturn hook ( [something]() { DestroySomething(something); } );Copy-initializing constructor call:
Atreturn hook = [something]() { DestroySomething(something); };Direct-list-initializing constructor call:
Atreturn hook { [something]() { DestroySomething(something); }};
Now the question: to my best knowledge, the method #1 and #2 should be allowed as they are theoretically the same thing, provided that there's no explicit at the constructor, while #3 should not be allowed because this syntax prevents conversions (at least it's so for int if you tried int{2.1}).
However, gcc 4.9 allows method #1 and #3, but not #2 (and says conversion from '...::<lambda()>' to non-scalar 'Atreturn' type requested). This sounds crazy because it normally happens only if you have explicit constructor. Can anybody explain, why?
Aucun commentaire:
Enregistrer un commentaire