Commit 489e1107 authored by Max Kellermann's avatar Max Kellermann

util/WritableBuffer: add ConstBuffer cast operator

parent 5e2af15e
/* /*
* Copyright (C) 2013-2017 Max Kellermann <max.kellermann@gmail.com> * Copyright (C) 2013-2018 Max Kellermann <max.kellermann@gmail.com>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#ifndef WRITABLE_BUFFER_HXX #ifndef WRITABLE_BUFFER_HXX
#define WRITABLE_BUFFER_HXX #define WRITABLE_BUFFER_HXX
#include "ConstBuffer.hxx"
#include "Compiler.h" #include "Compiler.h"
#include <cstddef> #include <cstddef>
...@@ -60,6 +61,10 @@ struct WritableBuffer<void> { ...@@ -60,6 +61,10 @@ struct WritableBuffer<void> {
constexpr WritableBuffer(pointer_type _data, size_type _size) constexpr WritableBuffer(pointer_type _data, size_type _size)
:data(_data), size(_size) {} :data(_data), size(_size) {}
constexpr operator ConstBuffer<void>() const noexcept {
return {data, size};
}
constexpr bool IsNull() const { constexpr bool IsNull() const {
return data == nullptr; return data == nullptr;
} }
...@@ -113,6 +118,10 @@ struct WritableBuffer { ...@@ -113,6 +118,10 @@ struct WritableBuffer {
constexpr WritableBuffer(T (&_data)[_size]) constexpr WritableBuffer(T (&_data)[_size])
:data(_data), size(_size) {} :data(_data), size(_size) {}
constexpr operator ConstBuffer<T>() const noexcept {
return {data, size};
}
/** /**
* Cast a WritableBuffer<void> to a WritableBuffer<T>, * Cast a WritableBuffer<void> to a WritableBuffer<T>,
* rounding down to the next multiple of T's size. * rounding down to the next multiple of T's size.
......
Markdown is supported
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