From 95d9587ea76613d2f48f1400851155a560f14177 Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Thu, 21 Apr 2022 09:10:14 -0400 Subject: [PATCH] Use span from Boost.Core --- .../boost/beast/core/detail/type_traits.hpp | 21 -- include/boost/beast/core/span.hpp | 195 +----------------- test/beast/core/span.cpp | 19 -- 3 files changed, 2 insertions(+), 233 deletions(-) diff --git a/include/boost/beast/core/detail/type_traits.hpp b/include/boost/beast/core/detail/type_traits.hpp index e94abbb1..8e028004 100644 --- a/include/boost/beast/core/detail/type_traits.hpp +++ b/include/boost/beast/core/detail/type_traits.hpp @@ -75,27 +75,6 @@ using aligned_union_t = //------------------------------------------------------------------------------ -// for span -template -struct is_contiguous_container: std::false_type {}; - -template -struct is_contiguous_container() = std::declval().size(), - std::declval() = std::declval().data()), - typename std::enable_if< - std::is_same< - typename std::remove_cv::type, - typename std::remove_cv< - typename std::remove_pointer< - decltype(std::declval().data()) - >::type - >::type - >::value - >::type>>: std::true_type -{}; - template T launder_cast(U* u) { diff --git a/include/boost/beast/core/span.hpp b/include/boost/beast/core/span.hpp index 55a1454e..8f66a368 100644 --- a/include/boost/beast/core/span.hpp +++ b/include/boost/beast/core/span.hpp @@ -11,203 +11,12 @@ #define BOOST_BEAST_CORE_SPAN_HPP #include -#include -#include -#include -#include -#include +#include namespace boost { namespace beast { -/** A range of bytes expressed as a ContiguousContainer - - This class implements a non-owning reference to a storage - area of a certain size and having an underlying integral - type with size of 1. - - @tparam T The type pointed to by span iterators -*/ -template -class span -{ - T* data_ = nullptr; - std::size_t size_ = 0; - -public: - /// The type of value, including cv qualifiers - using element_type = T; - - /// The type of value of each span element - using value_type = typename std::remove_const::type; - - /// The type of integer used to index the span - using index_type = std::ptrdiff_t; - - /// A pointer to a span element - using pointer = T*; - - /// A reference to a span element - using reference = T&; - - /// The iterator used by the container - using iterator = pointer; - - /// The const pointer used by the container - using const_pointer = T const*; - - /// The const reference used by the container - using const_reference = T const&; - - /// The const iterator used by the container - using const_iterator = const_pointer; - - /// Constructor - span() = default; - - /// Constructor - span(span const&) = default; - - /// Assignment - span& operator=(span const&) = default; - - /** Constructor - - @param data A pointer to the beginning of the range of elements - - @param size The number of elements pointed to by `data` - */ - span(T* data, std::size_t size) - : data_(data), size_(size) - { - } - - /** Constructor - - @param container The container to construct from - */ - template::value>::type -#endif - > - explicit - span(ContiguousContainer&& container) - : data_(container.data()) - , size_(container.size()) - { - } - -#if ! BOOST_BEAST_DOXYGEN - template - explicit - span(std::basic_string& s) - : data_(&s[0]) - , size_(s.size()) - { - } - - template - explicit - span(std::basic_string const& s) - : data_(s.data()) - , size_(s.size()) - { - } -#endif - - /** Assignment - - @param container The container to assign from - */ - template -#if BOOST_BEAST_DOXYGEN - span& -#else - typename std::enable_if::value, - span&>::type -#endif - operator=(ContiguousContainer&& container) - { - data_ = container.data(); - size_ = container.size(); - return *this; - } - -#if ! BOOST_BEAST_DOXYGEN - template - span& - operator=(std::basic_string< - CharT, Traits, Allocator>& s) - { - data_ = &s[0]; - size_ = s.size(); - return *this; - } - - template - span& - operator=(std::basic_string< - CharT, Traits, Allocator> const& s) - { - data_ = s.data(); - size_ = s.size(); - return *this; - } -#endif - - /// Returns `true` if the span is empty - bool - empty() const - { - return size_ == 0; - } - - /// Returns a pointer to the beginning of the span - T* - data() const - { - return data_; - } - - /// Returns the number of elements in the span - std::size_t - size() const - { - return size_; - } - - /// Returns an iterator to the beginning of the span - const_iterator - begin() const - { - return data_; - } - - /// Returns an iterator to the beginning of the span - const_iterator - cbegin() const - { - return data_; - } - - /// Returns an iterator to one past the end of the span - const_iterator - end() const - { - return data_ + size_; - } - - /// Returns an iterator to one past the end of the span - const_iterator - cend() const - { - return data_ + size_; - } -}; +using boost::span; } // beast } // boost diff --git a/test/beast/core/span.cpp b/test/beast/core/span.cpp index 96b6a774..f6012dbf 100644 --- a/test/beast/core/span.cpp +++ b/test/beast/core/span.cpp @@ -21,25 +21,6 @@ namespace beast { class span_test : public beast::unit_test::suite { public: - BOOST_STATIC_ASSERT( - detail::is_contiguous_container< - string_view, char const>::value); - - struct base {}; - struct derived : base {}; - - BOOST_STATIC_ASSERT(detail::is_contiguous_container< - std::vector, char>::value); - - BOOST_STATIC_ASSERT(detail::is_contiguous_container< - std::vector, char const>::value); - - BOOST_STATIC_ASSERT(! detail::is_contiguous_container< - std::vector, base>::value); - - BOOST_STATIC_ASSERT(! detail::is_contiguous_container< - std::vector, base const>::value); - void testSpan() {