diff options
author | Max Kellermann <max@musicpd.org> | 2018-08-20 15:36:50 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-08-20 15:36:50 +0200 |
commit | 489e11072e1608ec6b8bc9decdb38aaeb9cc05c8 (patch) | |
tree | a64e161657bb599c85a301af36bab1dd408cc4ef /src/util | |
parent | 5e2af15e94fa80bbe68ede1231181ea1bc5c0e71 (diff) |
util/WritableBuffer: add ConstBuffer cast operator
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/WritableBuffer.hxx | 11 |
1 files changed, 10 insertions, 1 deletions
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 <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 * 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 <cstddef> @@ -60,6 +61,10 @@ struct WritableBuffer<void> { constexpr WritableBuffer(pointer_type _data, size_type _size) :data(_data), size(_size) {} + constexpr operator ConstBuffer<void>() 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<T>() const noexcept { + return {data, size}; + } + /** * Cast a WritableBuffer<void> to a WritableBuffer<T>, * rounding down to the next multiple of T's size. |