From ebe4cb0bdeabd06a31072547af47cacaab7f78c0 Mon Sep 17 00:00:00 2001 From: Lexi Winter Date: Wed, 2 Jul 2025 05:49:47 +0100 Subject: replace nihil::generator the new implementation is much simpler and PD-licensed. the only downside is it doesn't support elements_of. while here, move it to nihil.core. --- nihil.generator/manual_lifetime.ccm | 114 ------------------------------------ 1 file changed, 114 deletions(-) delete mode 100644 nihil.generator/manual_lifetime.ccm (limited to 'nihil.generator/manual_lifetime.ccm') diff --git a/nihil.generator/manual_lifetime.ccm b/nihil.generator/manual_lifetime.ccm deleted file mode 100644 index 44bc0a8..0000000 --- a/nihil.generator/manual_lifetime.ccm +++ /dev/null @@ -1,114 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// 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) -/////////////////////////////////////////////////////////////////////////////// - -export module nihil.generator:manual_lifetime; - -import nihil.std; - -namespace nihil { - -template -struct manual_lifetime { - manual_lifetime() noexcept {} - ~manual_lifetime() {} - - template - auto construct(this manual_lifetime &self, Args && ...args) - noexcept(std::is_nothrow_constructible_v) - -> T & - { - return *::new (static_cast(std::addressof(self.m_value))) - T(static_cast(args)...); - } - - void destruct(this manual_lifetime &self) - noexcept(std::is_nothrow_destructible_v) - { - self.m_value.~T(); - } - - auto get(this manual_lifetime &self) noexcept -> T & - { - return self.m_value; - } - - auto get(this manual_lifetime &&self) noexcept -> T && - { - return static_cast(self.m_value); - } - - auto get(this manual_lifetime const &self) noexcept -> T const & - { - return self.m_value; - } - - auto get(this manual_lifetime const &&self) noexcept -> T const && - { - return static_cast(self.m_value); - } - -private: - union { - std::remove_const_t m_value; - }; -}; - -template -struct manual_lifetime { - manual_lifetime() noexcept = default; - ~manual_lifetime() = default; - - auto construct(this manual_lifetime &self, T &value) noexcept -> T & - { - self.m_value = std::addressof(value); - return value; - } - - auto destruct(this manual_lifetime &) noexcept -> void - { - } - - auto get(this manual_lifetime const &self) noexcept -> T & - { - return *self.m_value; - } - -private: - T *m_value = nullptr; -}; - -template -struct manual_lifetime { - manual_lifetime() noexcept = default; - ~manual_lifetime() = default; - - auto construct(this manual_lifetime &self, T &&value) noexcept -> T && - { - self.m_value = std::addressof(value); - return static_cast(value); - } - - void destruct(this manual_lifetime &) noexcept - { - } - - auto get(this manual_lifetime const &self) noexcept -> T && - { - return static_cast(*self.m_value); - } - -private: - T* m_value = nullptr; -}; - -} -- cgit v1.2.3