memory/buffer/traits: add a simple buffer concept

This commit is contained in:
Danny Robson 2018-12-19 17:15:51 +11:00
parent 8f2d036123
commit 4e055f5f0b
2 changed files with 44 additions and 0 deletions

View File

@ -351,6 +351,7 @@ list (
matrix.hpp matrix.hpp
memory/buffer/simple.cpp memory/buffer/simple.cpp
memory/buffer/simple.hpp memory/buffer/simple.hpp
memory/buffer/traits.hpp
memory/deleter.cpp memory/deleter.cpp
memory/deleter.hpp memory/deleter.hpp
nocopy.hpp nocopy.hpp

43
memory/buffer/traits.hpp Normal file
View File

@ -0,0 +1,43 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright 2018 Danny Robson <danny@nerdcruft.net>
*/
#pragma once
#include <type_traits>
namespace cruft::memory::buffer {
///////////////////////////////////////////////////////////////////////////
/// A trait that evaluates to true if the queried type models cruft::allocator
template <
typename BufferT,
typename = std::void_t<>
>
struct is_buffer
: public std::false_type
{ };
//-------------------------------------------------------------------------
template <typename BufferT>
struct is_buffer<BufferT,
std::void_t<
// Provides aligned and unaligned allocation
decltype(std::declval<BufferT> ().begin ()),
decltype(std::declval<BufferT> ().end ()),
decltype(std::declval<BufferT> ().size ()),
void
>
> : public std::true_type
{ };
//-------------------------------------------------------------------------
template <typename BufferT>
constexpr auto is_buffer_v = is_buffer<BufferT>::value;
}