mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 19:15:54 +00:00
* Concepts split up into individual files * Function definitions moved to .ipp files * Add more tests to fill gaps in coverage * Fix documentation Xsl
141 lines
4.2 KiB
C++
141 lines
4.2 KiB
C++
//
|
|
// Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com)
|
|
//
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
//
|
|
|
|
#ifndef BEAST_DETAIL_BUFFER_CONCEPTS_HPP
|
|
#define BEAST_DETAIL_BUFFER_CONCEPTS_HPP
|
|
|
|
#include <boost/asio/buffer.hpp>
|
|
#include <iterator>
|
|
#include <type_traits>
|
|
|
|
namespace beast {
|
|
namespace detail {
|
|
|
|
// Types that meet the requirements,
|
|
// for use with std::declval only.
|
|
template<class BufferType>
|
|
struct BufferSequence
|
|
{
|
|
using value_type = BufferType;
|
|
using const_iterator = BufferType const*;
|
|
~BufferSequence();
|
|
BufferSequence(BufferSequence const&) = default;
|
|
const_iterator begin() const noexcept;
|
|
const_iterator end() const noexcept;
|
|
};
|
|
using ConstBufferSequence =
|
|
BufferSequence<boost::asio::const_buffer>;
|
|
using MutableBufferSequence =
|
|
BufferSequence<boost::asio::mutable_buffer>;
|
|
|
|
template<class T, class BufferType>
|
|
class is_BufferSequence
|
|
{
|
|
template<class U, class R = std::is_convertible<
|
|
typename U::value_type, BufferType> >
|
|
static R check1(int);
|
|
template<class>
|
|
static std::false_type check1(...);
|
|
using type1 = decltype(check1<T>(0));
|
|
|
|
template<class U, class R = std::is_base_of<
|
|
#if 0
|
|
std::bidirectional_iterator_tag,
|
|
typename std::iterator_traits<
|
|
typename U::const_iterator>::iterator_category>>
|
|
#else
|
|
// workaround:
|
|
// boost::asio::detail::consuming_buffers::const_iterator
|
|
// is not bidirectional
|
|
std::forward_iterator_tag,
|
|
typename std::iterator_traits<
|
|
typename U::const_iterator>::iterator_category>>
|
|
#endif
|
|
static R check2(int);
|
|
template<class>
|
|
static std::false_type check2(...);
|
|
using type2 = decltype(check2<T>(0));
|
|
|
|
template<class U, class R = typename
|
|
std::is_convertible<decltype(
|
|
std::declval<U>().begin()),
|
|
typename U::const_iterator>::type>
|
|
static R check3(int);
|
|
template<class>
|
|
static std::false_type check3(...);
|
|
using type3 = decltype(check3<T>(0));
|
|
|
|
template<class U, class R = typename std::is_convertible<decltype(
|
|
std::declval<U>().end()),
|
|
typename U::const_iterator>::type>
|
|
static R check4(int);
|
|
template<class>
|
|
static std::false_type check4(...);
|
|
using type4 = decltype(check4<T>(0));
|
|
|
|
public:
|
|
using type = std::integral_constant<bool,
|
|
std::is_copy_constructible<T>::value &&
|
|
std::is_destructible<T>::value &&
|
|
type1::value && type2::value &&
|
|
type3::value && type4::value>;
|
|
};
|
|
|
|
template<class T>
|
|
class is_Streambuf
|
|
{
|
|
template<class U, class R = std::integral_constant<
|
|
bool, is_BufferSequence<decltype(
|
|
std::declval<U>().prepare(1)),
|
|
boost::asio::mutable_buffer>::type::value>>
|
|
static R check1(int);
|
|
template<class>
|
|
static std::false_type check1(...);
|
|
using type1 = decltype(check1<T>(0));
|
|
|
|
template<class U, class R = std::integral_constant<
|
|
bool, is_BufferSequence<decltype(
|
|
std::declval<U>().data()),
|
|
boost::asio::const_buffer>::type::value>>
|
|
static R check2(int);
|
|
template<class>
|
|
static std::false_type check2(...);
|
|
using type2 = decltype(check2<T>(0));
|
|
|
|
template<class U, class R = decltype(
|
|
std::declval<U>().commit(1), std::true_type{})>
|
|
static R check3(int);
|
|
template<class>
|
|
static std::false_type check3(...);
|
|
using type3 = decltype(check3<T>(0));
|
|
|
|
template<class U, class R = decltype(
|
|
std::declval<U>().consume(1), std::true_type{})>
|
|
static R check4(int);
|
|
template<class>
|
|
static std::false_type check4(...);
|
|
using type4 = decltype(check4<T>(0));
|
|
|
|
template<class U, class R = std::is_same<decltype(
|
|
std::declval<U>().size()), std::size_t>>
|
|
static R check5(int);
|
|
template<class>
|
|
static std::false_type check5(...);
|
|
using type5 = decltype(check5<T>(0));
|
|
|
|
public:
|
|
using type = std::integral_constant<bool,
|
|
type1::value && type2::value &&
|
|
type3::value && type4::value &&
|
|
type5::value>;
|
|
};
|
|
|
|
} // detail
|
|
} // beast
|
|
|
|
#endif
|