From 489e11072e1608ec6b8bc9decdb38aaeb9cc05c8 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 20 Aug 2018 15:36:50 +0200 Subject: [PATCH] util/WritableBuffer: add ConstBuffer cast operator --- src/util/WritableBuffer.hxx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/util/WritableBuffer.hxx b/src/util/WritableBuffer.hxx index 605ccebe0..696ae8910 100644 --- a/src/util/WritableBuffer.hxx +++ b/src/util/WritableBuffer.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2017 Max Kellermann + * Copyright (C) 2013-2018 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -30,6 +30,7 @@ #ifndef WRITABLE_BUFFER_HXX #define WRITABLE_BUFFER_HXX +#include "ConstBuffer.hxx" #include "Compiler.h" #include @@ -60,6 +61,10 @@ struct WritableBuffer { constexpr WritableBuffer(pointer_type _data, size_type _size) :data(_data), size(_size) {} + constexpr operator ConstBuffer() const noexcept { + return {data, size}; + } + constexpr bool IsNull() const { return data == nullptr; } @@ -113,6 +118,10 @@ struct WritableBuffer { constexpr WritableBuffer(T (&_data)[_size]) :data(_data), size(_size) {} + constexpr operator ConstBuffer() const noexcept { + return {data, size}; + } + /** * Cast a WritableBuffer to a WritableBuffer, * rounding down to the next multiple of T's size.