Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.


// Copyright (c) 2016-2019 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
// Official repository:
// This is a derivative work based on Zlib, copyright below:
    Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler

    This software is provided 'as-is', without any express or implied
    warranty.  In no event will the authors be held liable for any damages
    arising from the use of this software.

    Permission is granted to anyone to use this software for any purpose,
    including commercial applications, and to alter it and redistribute it
    freely, subject to the following restrictions:

    1. The origin of this software must not be misrepresented; you must not
       claim that you wrote the original software. If you use this software
       in a product, an acknowledgment in the product documentation would be
       appreciated but is not required.
    2. Altered source versions must be plainly marked as such, and must not be
       misrepresented as being the original software.
    3. This notice may not be removed or altered from any source distribution.

    Jean-loup Gailly        Mark Adler

    The data format used by the zlib library is described by RFCs (Request for
    Comments) 1950 to 1952 in the files
    (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).


#include <cstdint>
#include <type_traits>

namespace boost {
namespace beast {
namespace zlib {
namespace detail {

struct ranges
    template<bool isConst>
    struct range
        using iter_t =
            typename std::conditional<isConst,
                std::uint8_t const*,

        iter_t first;
        iter_t last;
        iter_t next;

        // total bytes in range
        size() const
            return last - first;

        // bytes consumed
        used() const
            return next - first;

        // bytes remaining
        avail() const
            return last - next;

    range<true> in;
    range<false> out;

// Clamp u to v where u and v are different types
template<class U, class V>
U clamp(U u, V v)
    if(u > v)
        u = static_cast<U>(v);
    return u;

} // detail
} // zlib
} // beast
} // boost