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:
parent
abfc3c7878
commit
e48aebb503
14
io.hpp
14
io.hpp
@ -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
9
io.ipp
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user