C++14 and later CRTP templates for defining iterators, views, and containers
An updated C++20-friendly version of the iterator_facade
and
iterator_adaptor
parts of Boost.Iterator (now called iterator_interface
);
a pre-C++20 version of C++20's view_interface
; and a new template called
container_interface
, meant to aid the creation of new containers; all
targeting standardization. This library requires at least C++14.
For the iterator portion -- if you need to write an iterator, iterator_interface
turns this:
struct repeated_chars_iterator
{
using value_type = char;
using difference_type = std::ptrdiff_t;
using pointer = char const *;
using reference = char const;
using iterator_category = std::random_access_iterator_tag;
constexpr repeated_chars_iterator() noexcept :
first_(nullptr),
size_(0),
n_(0)
{}
constexpr repeated_chars_iterator(
char const * first,
difference_type size,
difference_type n) noexcept :
first_(first),
size_(size),
n_(n)
{}
constexpr reference operator*() const noexcept
{
return first_[n_ % size_];
}
constexpr value_type operator[](difference_type n) const noexcept
{
return first_[(n_ + n) % size_];
}
constexpr repeated_chars_iterator & operator++() noexcept
{
++n_;
return *this;
}
constexpr repeated_chars_iterator operator++(int)noexcept
{
repeated_chars_iterator retval = *this;
++*this;
return retval;
}
constexpr repeated_chars_iterator & operator+=(difference_type n) noexcept
{
n_ += n;
return *this;
}
constexpr repeated_chars_iterator & operator--() noexcept
{
--n_;
return *this;
}
constexpr repeated_chars_iterator operator--(int)noexcept
{
repeated_chars_iterator retval = *this;
--*this;
return retval;
}
constexpr repeated_chars_iterator & operator-=(difference_type n) noexcept
{
n_ -= n;
return *this;
}
friend constexpr bool operator==(
repeated_chars_iterator lhs, repeated_chars_iterator rhs) noexcept
{
return lhs.first_ == rhs.first_ && lhs.n_ == rhs.n_;
}
friend constexpr bool operator!=(
repeated_chars_iterator lhs, repeated_chars_iterator rhs) noexcept
{
return !(lhs == rhs);
}
friend constexpr bool operator<(
repeated_chars_iterator lhs, repeated_chars_iterator rhs) noexcept
{
return lhs.first_ == rhs.first_ && lhs.n_ < rhs.n_;
}
friend constexpr bool operator<=(
repeated_chars_iterator lhs, repeated_chars_iterator rhs) noexcept
{
return lhs == rhs || lhs < rhs;
}
friend constexpr bool operator>(
repeated_chars_iterator lhs, repeated_chars_iterator rhs) noexcept
{
return rhs < lhs;
}
friend constexpr bool operator>=(
repeated_chars_iterator lhs, repeated_chars_iterator rhs) noexcept
{
return rhs <= lhs;
}
friend constexpr repeated_chars_iterator
operator+(repeated_chars_iterator lhs, difference_type rhs) noexcept
{
return lhs += rhs;
}
friend constexpr repeated_chars_iterator
operator+(difference_type lhs, repeated_chars_iterator rhs) noexcept
{
return rhs += lhs;
}
friend constexpr repeated_chars_iterator
operator-(repeated_chars_iterator lhs, difference_type rhs) noexcept
{
return lhs -= rhs;
}
friend constexpr difference_type operator-(
repeated_chars_iterator lhs, repeated_chars_iterator rhs) noexcept
{
return lhs.n_ - rhs.n_;
}
private:
char const * first_;
difference_type size_;
difference_type n_;
};
into this:
struct repeated_chars_iterator : boost::stl_interfaces::iterator_interface<
repeated_chars_iterator,
std::random_access_iterator_tag,
char,
char>
{
constexpr repeated_chars_iterator() noexcept :
first_(nullptr),
size_(0),
n_(0)
{}
constexpr repeated_chars_iterator(
char const * first, difference_type size, difference_type n) noexcept :
first_(first),
size_(size),
n_(n)
{}
constexpr char operator*() const noexcept { return first_[n_ % size_]; }
constexpr repeated_chars_iterator & operator+=(std::ptrdiff_t i) noexcept
{
n_ += i;
return *this;
}
constexpr auto operator-(repeated_chars_iterator other) const noexcept
{
return n_ - other.n_;
}
private:
char const * first_;
difference_type size_;
difference_type n_;
};
The code size savings are even more dramatic for view_interface
and
container_interface
! If you don't ever write iterators, range views, or
containers, this is not for you.
Online docs: https://boostorg.github.io/stl_interfaces.
This library includes a temporary implementation for those who wish to experiment with
a concept-constrained version before C++20 is widely implemented. Casey Carter's cmcstl2
is an implementation of the std::ranges
portion of the C++20 standard library. To use it:
-
check out the cmcstl2 branch of this library; then
-
put its headers in your include path, so that they can be included with
#include <stl2/foo.hpp>
; and -
build with GCC 8 or 9, including the
-fconcepts
and-std=c++2a
flags.
GCC 8 and 9 are the only compilers with an adequate concepts implementation at the time of this writing.
version | 1.77.0+1 |
---|---|
license | BSL-1.0Boost Software License 1.0 |
repository | https://pkg.cppget.org/1/stable |
download | libboost-stl-interfaces-1.77.0+1.tar.gz |
sha256 | 947fa89c06999f38921608b23e604207d2068e528044546b4cefcd8336913499 |
project | boost |
---|---|
url | github.com/boostorg/stl_interfaces |
doc-url | www.boost.org/doc/libs/1_77_0/libs/stl_interfaces |
package-url | github.com/build2-packaging/boost |
boost-users@lists.boost.orgMailing list | |
package-email | packaging@build2.orgMailing list |
topics | C++Boost |
Depends (2)
libboost-assert == 1.77.0 | |
libboost-config == 1.77.0 |
Builds
toolchain | public-0.16.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_11-gcc_12 |
timestamp | 2024-05-01 14:48:50 UTC (01 05:19:13 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-apple-darwin22.5.0 |
tgt config | macos_13-clang_14.0-static_O3 |
timestamp | 2024-05-01 11:17:11 UTC (01 08:50:53 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-apple-darwin22.5.0 |
tgt config | macos_13-clang_14.0-O3 |
timestamp | 2024-05-01 11:16:23 UTC (01 08:51:41 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-apple-darwin22.5.0 |
tgt config | macos_13-clang_14.0 |
timestamp | 2024-05-01 11:15:45 UTC (01 08:52:19 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-gcc_13-O3 |
timestamp | 2024-05-01 10:34:34 UTC (01 09:33:30 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-gcc_13-static_O3 |
timestamp | 2024-05-01 10:34:08 UTC (01 09:33:56 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-gcc_13-ndebug_O3 |
timestamp | 2024-05-01 10:34:06 UTC (01 09:33:57 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-gcc_13 |
timestamp | 2024-05-01 10:33:36 UTC (01 09:34:28 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-clang_15_libc++ |
timestamp | 2024-05-01 10:21:51 UTC (01 09:46:12 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-clang_15 |
timestamp | 2024-05-01 10:21:31 UTC (01 09:46:32 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_fedora_37-gcc_12.2-bindist |
timestamp | 2024-05-01 01:03:39 UTC (01 19:04:25 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-clang_16_libc++-static_O3 |
timestamp | 2024-04-30 19:38:28 UTC (02 00:29:35 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-clang_16_libc++-O3 |
timestamp | 2024-04-30 19:24:49 UTC (02 00:43:15 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-clang_16_libc++ |
timestamp | 2024-04-30 19:19:35 UTC (02 00:48:29 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-gcc_12-bindist |
timestamp | 2024-04-30 18:02:05 UTC (02 02:05:59 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-microsoft-win32-msvc14.3 |
tgt config | windows_10-clang_16.0_llvm_msvc_17.6-static_O2 |
timestamp | 2024-04-30 16:41:31 UTC (02 03:26:33 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-microsoft-win32-msvc14.3 |
tgt config | windows_10-clang_16.0_llvm_msvc_17.6 |
timestamp | 2024-04-30 16:40:37 UTC (02 03:27:27 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-microsoft-win32-msvc14.3 |
tgt config | windows_10-clang_16.0_llvm_msvc_17.6-O2 |
timestamp | 2024-04-30 16:39:46 UTC (02 03:28:18 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-apple-darwin22.5.0 |
tgt config | macos_13-clang_15.0-static_O3 |
timestamp | 2024-04-30 16:37:10 UTC (02 03:30:54 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-apple-darwin22.5.0 |
tgt config | macos_13-clang_15.0-O3 |
timestamp | 2024-04-30 16:36:28 UTC (02 03:31:36 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-apple-darwin22.5.0 |
tgt config | macos_13-clang_15.0 |
timestamp | 2024-04-30 16:35:43 UTC (02 03:32:20 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-clang_16.0_libc++-static_O3 |
timestamp | 2024-04-30 16:31:50 UTC (02 03:36:14 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-clang_16.0_libc++ |
timestamp | 2024-04-30 16:28:24 UTC (02 03:39:40 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-clang_16.0_libc++-O3 |
timestamp | 2024-04-30 16:28:10 UTC (02 03:39:53 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-microsoft-win32-msvc14.3 |
tgt config | windows_10-msvc_17.6-static_O2 |
timestamp | 2024-04-30 15:11:03 UTC (02 04:57:01 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-microsoft-win32-msvc14.3 |
tgt config | windows_10-msvc_17.6 |
timestamp | 2024-04-30 15:10:35 UTC (02 04:57:29 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-microsoft-win32-msvc14.3 |
tgt config | windows_10-msvc_17.6-O2 |
timestamp | 2024-04-30 15:10:19 UTC (02 04:57:45 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-w64-mingw32 |
tgt config | windows_10-gcc_12.2_mingw_w64-static_O2 |
timestamp | 2024-04-30 15:07:56 UTC (02 05:00:08 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-w64-mingw32 |
tgt config | windows_10-gcc_12.2_mingw_w64 |
timestamp | 2024-04-30 15:06:34 UTC (02 05:01:29 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-w64-mingw32 |
tgt config | windows_10-gcc_12.2_mingw_w64-O2 |
timestamp | 2024-04-30 15:06:34 UTC (02 05:01:29 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-microsoft-win32-msvc14.3 |
tgt config | windows_10-msvc_17.5 |
timestamp | 2024-04-30 14:46:25 UTC (02 05:21:39 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_11-gcc_12.1 |
timestamp | 2024-04-30 14:35:40 UTC (02 05:32:24 days ago) |
result | success | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-microsoft-win32-msvc14.3 |
tgt config | windows_10-clang_15.0_msvc_msvc_17.6 |
timestamp | 2024-04-30 11:20:29 UTC (02 08:47:35 days ago) |
result | warning (update) | warning (test-installed) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-clang_16 |
timestamp | 2024-04-30 11:12:53 UTC (02 08:55:11 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-clang_16-static_O3 |
timestamp | 2024-04-30 11:07:08 UTC (02 09:00:56 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-clang_16-O3 |
timestamp | 2024-04-30 11:05:28 UTC (02 09:02:35 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_fedora_38-gcc_13-bindist |
timestamp | 2024-04-30 11:00:42 UTC (02 09:07:22 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-clang_16.0-static_O3 |
timestamp | 2024-04-30 10:41:29 UTC (02 09:26:35 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-clang_16.0-O3 |
timestamp | 2024-04-30 10:39:13 UTC (02 09:28:51 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-clang_16.0 |
timestamp | 2024-04-30 10:38:47 UTC (02 09:29:17 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-freebsd13.2 |
tgt config | freebsd_13-clang_14.0 |
timestamp | 2024-04-30 10:27:53 UTC (02 09:40:11 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-gcc_13.1-O3 |
timestamp | 2024-04-30 10:27:52 UTC (02 09:40:12 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-gcc_13.1-static_O3 |
timestamp | 2024-04-30 10:27:43 UTC (02 09:40:21 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-gcc_13.1-ndebug_O3 |
timestamp | 2024-04-30 10:27:33 UTC (02 09:40:31 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-freebsd13.2 |
tgt config | freebsd_13-clang_14.0-static_O3 |
timestamp | 2024-04-30 10:27:30 UTC (02 09:40:33 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-gcc_13.1 |
timestamp | 2024-04-30 10:27:30 UTC (02 09:40:34 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-freebsd13.2 |
tgt config | freebsd_13-clang_14.0-O3 |
timestamp | 2024-04-30 10:27:07 UTC (02 09:40:57 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-clang_15.0 |
timestamp | 2024-04-30 10:26:24 UTC (02 09:41:40 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-clang_15.0_libc++ |
timestamp | 2024-04-30 10:26:07 UTC (02 09:41:56 days ago) |
result | error (update) | log | rebuild |
toolchain | public-0.16.0 |
---|---|
target | x86_64-freebsd12.4 |
tgt config | freebsd_12-clang_13.0 |
timestamp | 2024-04-30 10:25:43 UTC (02 09:42:21 days ago) |
result | error (update) | log | rebuild |
target | x86_64-apple-darwin22.5.0 |
---|---|
tgt config | macos_13-gcc_13_homebrew |
result | excluded (https://github) |
target | x86_64-apple-darwin22.5.0 |
---|---|
tgt config | macos_13-gcc_13_homebrew-O3 |
result | excluded (https://github) |
target | x86_64-apple-darwin22.5.0 |
---|---|
tgt config | macos_13-gcc_13_homebrew-static_O3 |
result | excluded (https://github) |