Bjorn Reese wrote
I think boost/serialization/list.hpp checks for the default constructor in the wrong way. If you use std::vector instead of std::list, then it compiles.
Unfortunately this isn't exactly true. I had it using an std::vector before using std::list, which I ultimately sent and it fails as well. I have checked std::list, std::vector, std::forward_list, std::unordered_map, std::map, and std::unordered_set. Robert Ramey wrote
I've recently spent some time on this and I believe that I've now fixed it. I had some difficulty with "is_default_constructible".
Unfortunately this isn't where the problem is coming from, at least not on
MSVC++2013.
The problem with std::vector and std::list (and the other sequential,
non-associative containers) is that regardless of is_default_contructible<T>
with T being non-default constructible, the compiler will generate code that
calls T::T() and will have a compiler error because of it. Specifically, you
call std::vector::resize, std::list::resize and std::forward_list::resize
with the second argument being default which results in the generation of
code calling T::T().
Inside boost/serialization/list.hpp and the load function:
if(detail::is_default_constructible<U>()){
t.resize(count);
/////////////////////////////////////////////////////// <- here
typename std::list::iterator hint;
hint = t.begin();
while(count-- > 0){
ar >> boost::serialization::make_nvp("item", *hint++);
}
}
The problem is when U is non-default constructible. That if will never stop
the code generation under it even if is_default_constructible<U> will always
be false. std::list::resize has the signature "void resize (size_type n,
value_type val = value_type())"; this is where the compiler error originates
from, at least for std::list, std::vector and std::forward_list.
The best solution I thought of would be to change the basic if to a tag
dispatch method, or to utilize SFINAE, to preclude the compiler from
generating code calling U::U().
std::vector also has an additional layer above it using tag dispatch to
select between unoptimized and optimized algorithms. The above will work for
both of those algorithms (the problem is the same, IE they're both calling
resize).
The problem for the associative containers is a bit different, but
(potentially?) easier to fix.
Inside of boost\serialization\unordered_map.hpp:
struct archive_input_unordered_map
{
inline void operator()(
Archive &ar,
Container &s,
const unsigned int v
){
typedef typename Container::value_type type;
detail::stack_construct