disable binary<std::vector<T>> specialization if T is not default constructible

This commit is contained in:
Max Lyon
2021-03-15 17:11:57 +01:00
parent 5aa027d172
commit d017c03c62
3 changed files with 10 additions and 8 deletions

View File

@@ -98,7 +98,7 @@ namespace IO {
/// - std::vector<T> (requires a specialization for T) /// - std::vector<T> (requires a specialization for T)
/// ///
/// \todo Complete documentation of members /// \todo Complete documentation of members
template < typename T > struct binary template < typename T, typename = void > struct binary
{ {
typedef T value_type; typedef T value_type;
@@ -116,15 +116,17 @@ template < typename T > struct binary
/// Store a value of T and return the number of bytes written /// Store a value of T and return the number of bytes written
static static
size_t store( std::ostream& /* _os */, size_t store( std::ostream& /* _os */,
const value_type& /* _v */, const value_type& /* _v */,
bool /* _swap=false */) bool /* _swap */ = false ,
bool /* store_size */ = true ) // for vectors
{ X; return 0; } { X; return 0; }
/// Restore a value of T and return the number of bytes read /// Restore a value of T and return the number of bytes read
static static
size_t restore( std::istream& /* _is */, size_t restore( std::istream& /* _is */,
value_type& /* _v */, value_type& /* _v */,
bool /* _swap=false */) bool /* _swap */ = false ,
bool /* store_size */ = true ) // for vectors
{ X; return 0; } { X; return 0; }
}; };

View File

@@ -325,7 +325,7 @@ struct FunctorRestore {
}; };
template <typename T> template <typename T>
struct binary< std::vector< T > > { struct binary< std::vector< T >, typename std::enable_if<std::is_default_constructible<T>::value>::type > {
typedef std::vector< T > value_type; typedef std::vector< T > value_type;
typedef typename value_type::value_type elem_type; typedef typename value_type::value_type elem_type;

View File

@@ -102,7 +102,7 @@ size_t size_of(bool _store_size)
{ return binary< std::vector<T> >::size_of(_store_size); } { return binary< std::vector<T> >::size_of(_store_size); }
template <typename T> inline template <typename T> inline
size_t store( std::ostream& _os, const T& _v, bool _swap=false) size_t store( std::ostream& _os, const T& _v, bool _swap =false)
{ return binary< T >::store( _os, _v, _swap ); } { return binary< T >::store( _os, _v, _swap ); }
template <typename T> inline template <typename T> inline
@@ -110,7 +110,7 @@ size_t store( std::ostream& _os, const std::vector<T>& _v, bool _swap=false, boo
{ return binary< std::vector<T> >::store( _os, _v, _swap, _store_size); } { return binary< std::vector<T> >::store( _os, _v, _swap, _store_size); }
template <typename T> inline template <typename T> inline
size_t restore( std::istream& _is, T& _v, bool _swap=false) size_t restore( std::istream& _is, T& _v, bool _swap = false)
{ return binary< T >::restore( _is, _v, _swap ); } { return binary< T >::restore( _is, _v, _swap ); }
template <typename T> inline template <typename T> inline