/////////////////////////////////////////////////////////////////////////////// // 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 export module nihil.generator:elements_of; import :util; namespace nihil { export template struct elements_of { explicit constexpr elements_of(Range &&range) noexcept requires std::is_default_constructible_v : m_range(static_cast(range)) { } constexpr elements_of(Range &&range, Allocator &&alloc) noexcept : m_range(static_cast(range)) , m_alloc(static_cast(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(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 elements_of(Range &&) -> elements_of; export template elements_of(Range &&, Allocator &&) -> elements_of; } // namespace nihil