io: remove lvalue write function

writing arbitrary lvalues is incredibly dangerous if we don't have total
coverage of suitable overloads. eg, we have accidentally written string
objects to file descriptors.

instead we prefer byte/char views which the user can create as desired.
there's a little more cognitive overhead here, but it's substantially
less dangerous in casual usage.
This commit is contained in:
Danny Robson 2017-12-19 18:10:05 +11:00
parent abfc3c7878
commit e48aebb503
2 changed files with 11 additions and 12 deletions

14
io.hpp
View File

@ -46,11 +46,19 @@ namespace util {
//-------------------------------------------------------------------------
void write (const posix::fd&, const void *restrict data, size_t bytes);
template <typename T>
void write (const posix::fd&, const T &data);
inline void
write (const posix::fd &dst, util::view<const char*> data)
{
write (dst, std::data (data), std::size (data));
}
template <typename T>
void write (const posix::fd&, const T *restrict first, const T *restrict last);
void write (const posix::fd &_fd, const T &data)
{
return write (_fd, make_view (data));
}
//-------------------------------------------------------------------------
class indenter : public std::streambuf {

9
io.ipp
View File

@ -23,15 +23,6 @@
#endif
namespace util {
//-------------------------------------------------------------------------
template <typename T>
void
write (const posix::fd &_fd, const T &data)
{
write (_fd, &data, sizeof (T));
}
//-------------------------------------------------------------------------
template <typename T>
void