2014-07-01 16 views
6

Il mio compilatore è clang 3.4, che supporta completamente C++ 14 e std::forward_list.Perché `return {};` non si applica a `std :: forward_list`?

#include <forward_list> 

struct A 
{ 
    A() 
    {} 

    explicit A(initializer_list<int>) 
    {} 
}; 

A f1() 
{ 
    return A(); // OK 
} 

A f2() 
{ 
    return {}; // OK 
} 

typedef std::forward_list<int> T; 

T f3() 
{ 
    return T(); // OK 
} 

T f4() 
{ 
    // error : converting to 'T {aka std::forward_list<int>}' from initializer 
    // list would use explicit constructor 'std::forward_list'  
    return {}; // ??? 
} 

Perché return {}; si applica ai std::forward_list?

risposta

18

Bene, anche se il compilatore C++ è 14-compatibile, la libreria standard non è :)

C++ 11 è:

explicit forward_list(const Allocator& alloc = Allocator()); 

mentre C++ 14 ha (dal library DR2193):

forward_list() : forward_list(Allocator()) {} 
explicit forward_list(const Allocator& alloc); 

Se si cambia A s' costruttore di default per explicit A(char* = nullptr) vedrete lo stesso comportamento.

Problemi correlati