Commit 3e56d034 authored by Martin Marinov's avatar Martin Marinov
Browse files

Fixed IOutputStream array/vector operator<<() for empty arrary/vector.

parent 74d08d55
......@@ -5,7 +5,9 @@
#include <string>
#include <vector>
#if (_MSC_VER >= 1900 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__))
#if (_MSC_VER >= 1700 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__))
#define STD_ARRAY_AVAILABLE
#include <array>
#endif
......@@ -52,7 +54,7 @@ public:
/*! Print an array of ElementT */
template <typename ElementT>
inline IOutputStream& print(const size_t _nmbr, const ElementT* _elems)
inline IOutputStream& print(const size_t _nmbr, const ElementT* const _elems)
{
print("[ ");
for (size_t i = 0; i < _nmbr; ++i)
......@@ -88,22 +90,32 @@ BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _os, const Command::Type
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _os,
const boost::filesystem::path& _path);
// IStream operator for std::vector<>
//! IStream operator for std::vector<>
template <typename ElementT>
IOutputStream& operator<<(IOutputStream& _os, const std::vector<ElementT>& _vec)
{
return _os.print(_vec.size(), &_vec[0]);
return _vec.empty() ? _os.print(0, (ElementT*)NULL) :
_os.print(_vec.size(), &_vec[0]);
}
#if (_MSC_VER >= 1900 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__))
// IStream operator for std::array<>
#ifdef STD_ARRAY_AVAILABLE
//! IStream operator for std::array<>
template <typename ElementT, size_t _nmbr>
IOutputStream& operator<<(IOutputStream& _os,
const std::array<ElementT, _nmbr>& _vec)
{
return _os.print(_nmbr, &_vec[0]);
}
#endif
//! Partial specialization for an empty std::array<>
template <typename ElementT>
IOutputStream& operator<<(IOutputStream& _os,
const std::array<ElementT, 0>& /*_vec*/)
{
return _os.print(0, (ElementT*)nullptr);
}
#endif// STD_ARRAY_AVAILABLE
// IStream operator for fixed size arrays
template <typename ElementT, size_t _nmbr>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment