forked from boostorg/endian
For the endian types, add stream inserters and extractors as requested during the formal review.
This commit is contained in:
1 parent
a1be441f8f
commit
c41521cead
6 files changed
+113
-26
No files matched your search
@@ -96,19 +96,25 @@ namespace boost
|
||||
# endif
|
||||
|
||||
# ifndef BOOST_NO_IO_COVER_OPERATORS
|
||||
// TODO: stream I/O needs to be templatized on the stream type, so will
|
||||
// work with wide streams, etc.
|
||||
|
||||
// Stream input and output.
|
||||
friend std::ostream& operator<<(std::ostream& s, const T& x)
|
||||
{ return s << +x; }
|
||||
friend std::istream& operator>>(std::istream& s, T& x)
|
||||
{
|
||||
IntegerType i;
|
||||
if (s >> i)
|
||||
x = i;
|
||||
return s;
|
||||
}
|
||||
// Stream inserter
|
||||
template <class charT, class traits>
|
||||
friend std::basic_ostream<charT, traits>&
|
||||
operator<<(std::basic_ostream<charT, traits>& os, const T& x)
|
||||
{
|
||||
return os << +x;
|
||||
}
|
||||
|
||||
// Stream extractor
|
||||
template <class charT, class traits>
|
||||
friend std::basic_istream<charT, traits>&
|
||||
operator>>(std::basic_istream<charT, traits>& is, T& x)
|
||||
{
|
||||
IntegerType i;
|
||||
if (is >> i)
|
||||
x = i;
|
||||
return is;
|
||||
}
|
||||
# endif
|
||||
};
|
||||
} // namespace endian
|
||||
|
||||
@@ -38,9 +38,9 @@
|
||||
#include <boost/predef/detail/endian_compat.h>
|
||||
#include <boost/endian/conversion.hpp>
|
||||
#define BOOST_MINIMAL_INTEGER_COVER_OPERATORS
|
||||
#define BOOST_NO_IO_COVER_OPERATORS
|
||||
//#define BOOST_NO_IO_COVER_OPERATORS
|
||||
#include <boost/endian/detail/cover_operators.hpp>
|
||||
#undef BOOST_NO_IO_COVER_OPERATORS
|
||||
//#undef BOOST_NO_IO_COVER_OPERATORS
|
||||
#undef BOOST_MINIMAL_INTEGER_COVER_OPERATORS
|
||||
#include <boost/type_traits/is_signed.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
@@ -90,7 +90,7 @@ namespace endian
|
||||
#endif
|
||||
BOOST_SCOPED_ENUM_START(align) {no, yes}; BOOST_SCOPED_ENUM_END
|
||||
|
||||
template <BOOST_SCOPED_ENUM(order) Order, typename T, std::size_t n_bits,
|
||||
template <BOOST_SCOPED_ENUM(order) Order, classname T, std::size_t n_bits,
|
||||
BOOST_SCOPED_ENUM(align) A = align::no>
|
||||
class endian;
|
||||
|
||||
|
||||
Reference in new issue
Block a user