diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-06-29 17:16:22 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-06-29 17:16:22 +0100 |
| commit | 4fa6821e0645ff61a9380cd090abff472205c630 (patch) | |
| tree | bd95f13b2dc0bd9692681f50c365d2914a520bfe /nihil.generator/elements_of.ccm | |
| parent | e5180acf5f2dfac788e8c12886095ed1ac66fae5 (diff) | |
| download | nihil-4fa6821e0645ff61a9380cd090abff472205c630.tar.gz nihil-4fa6821e0645ff61a9380cd090abff472205c630.tar.bz2 | |
add clang-tidy support
Diffstat (limited to 'nihil.generator/elements_of.ccm')
| -rw-r--r-- | nihil.generator/elements_of.ccm | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/nihil.generator/elements_of.ccm b/nihil.generator/elements_of.ccm new file mode 100644 index 0000000..0e34eb9 --- /dev/null +++ b/nihil.generator/elements_of.ccm @@ -0,0 +1,69 @@ +/////////////////////////////////////////////////////////////////////////////// +// Reference implementation of std::generator proposal P2168. +// +// See https://wg21.link/P2168 for details. +// +/////////////////////////////////////////////////////////////////////////////// +// Copyright Lewis Baker, Corentin Jabot +// +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. +// (See accompanying file LICENSE or http://www.boost.org/LICENSE_1_0.txt) +/////////////////////////////////////////////////////////////////////////////// + +module; + +#include <concepts> + +export module nihil.generator:elements_of; + +import :util; + +namespace nihil { + +export template <typename Range, typename Allocator = use_allocator_arg> +struct elements_of { + explicit constexpr elements_of(Range &&range) noexcept + requires std::is_default_constructible_v<Allocator> + : m_range(static_cast<Range &&>(range)) + { + } + + constexpr elements_of(Range &&range, Allocator &&alloc) noexcept + : m_range(static_cast<Range &&>(range)) + , m_alloc(static_cast<Allocator &&>(alloc)) + {} + + constexpr elements_of(elements_of &&) noexcept = default; + + constexpr elements_of(const elements_of &) = delete; + + constexpr auto operator=(this elements_of &, const elements_of &) + -> elements_of & = delete; + constexpr auto operator=(this elements_of &, elements_of &&) noexcept + -> elements_of & = delete; + + [[nodiscard]] constexpr auto + get(this elements_of const &self) noexcept -> Range && + { + return static_cast<Range &&>(self.m_range); + } + + [[nodiscard]] constexpr auto + get_allocator(this elements_of const &self) noexcept -> Allocator + { + return self.m_alloc; + } + +private: + [[no_unique_address]] Allocator m_alloc; + Range &&m_range; +}; + +export template <typename Range> +elements_of(Range &&) -> elements_of<Range>; + +export template <typename Range, typename Allocator> +elements_of(Range &&, Allocator &&) -> elements_of<Range, Allocator>; + +} // namespace nihil |
