@@ -893,6 +893,71 @@ public:
893893 using handle_type = std::coroutine_handle<>;
894894 using full_handle_type = std::coroutine_handle<promise_type>;
895895
896+ future (future const & p_other) = delete ;
897+ future& operator =(future const & p_other) = delete ;
898+
899+ /* *
900+ * @brief Default initialization for a void future
901+ *
902+ * This future will considered to be done on creation.
903+ */
904+ future ()
905+ requires (std::is_void_v<T>)
906+ : m_state(std::monostate{})
907+ {
908+ }
909+
910+ /* *
911+ * @brief Construct a future with a value
912+ *
913+ * This future will considered to be done and will contain just the value
914+ * passed into this.
915+ *
916+ * @tparam U - type that can construct a type T (which includes T itself)
917+ */
918+ template <typename U>
919+ constexpr future (U&& p_value) noexcept
920+ requires std::is_constructible_v<T, U&&>
921+ {
922+ m_state.template emplace <T>(std::forward<U>(p_value));
923+ };
924+
925+ constexpr future (future&& p_other) noexcept
926+ : m_state(std::exchange(p_other.m_state, std::monostate{}))
927+ {
928+ if (std::holds_alternative<handle_type>(m_state)) {
929+ auto handle = std::get<handle_type>(m_state);
930+ full_handle_type::from_address (handle.address ())
931+ .promise ()
932+ .set_object_address (&m_state);
933+ }
934+ }
935+
936+ constexpr future& operator =(future&& p_other) noexcept
937+ {
938+ if (this != &p_other) {
939+ m_state = std::exchange (p_other.m_state , std::monostate{});
940+ if (std::holds_alternative<handle_type>(m_state)) {
941+ auto handle = std::get<handle_type>(m_state);
942+ full_handle_type::from_address (handle.address ())
943+ .promise ()
944+ .set_object_address (&m_state);
945+ }
946+ }
947+ return *this ;
948+ }
949+
950+ constexpr ~future ()
951+ {
952+ if (std::holds_alternative<handle_type>(m_state)) {
953+ auto handle = std::get<handle_type>(m_state);
954+ full_handle_type::from_address (handle.address ())
955+ .promise ()
956+ .get_context ()
957+ .cancel ();
958+ }
959+ }
960+
896961 constexpr void resume () const
897962 {
898963 if (std::holds_alternative<handle_type>(m_state)) {
@@ -1023,52 +1088,6 @@ public:
10231088 return awaiter{ *this };
10241089 }
10251090
1026- template <typename U>
1027- constexpr future (U&& p_value) noexcept
1028- requires std::is_constructible_v<T, U&&>
1029- {
1030- m_state.template emplace <T>(std::forward<U>(p_value));
1031- };
1032-
1033- future (future const & p_other) = delete ;
1034- future& operator =(future const & p_other) = delete ;
1035-
1036- constexpr future (future&& p_other) noexcept
1037- : m_state(std::exchange(p_other.m_state, std::monostate{}))
1038- {
1039- if (std::holds_alternative<handle_type>(m_state)) {
1040- auto handle = std::get<handle_type>(m_state);
1041- full_handle_type::from_address (handle.address ())
1042- .promise ()
1043- .set_object_address (&m_state);
1044- }
1045- }
1046-
1047- constexpr future& operator =(future&& p_other) noexcept
1048- {
1049- if (this != &p_other) {
1050- m_state = std::exchange (p_other.m_state , std::monostate{});
1051- if (std::holds_alternative<handle_type>(m_state)) {
1052- auto handle = std::get<handle_type>(m_state);
1053- full_handle_type::from_address (handle.address ())
1054- .promise ()
1055- .set_object_address (&m_state);
1056- }
1057- }
1058- return *this ;
1059- }
1060-
1061- constexpr ~future ()
1062- {
1063- if (std::holds_alternative<handle_type>(m_state)) {
1064- auto handle = std::get<handle_type>(m_state);
1065- full_handle_type::from_address (handle.address ())
1066- .promise ()
1067- .get_context ()
1068- .cancel ();
1069- }
1070- }
1071-
10721091private:
10731092 friend promise_type;
10741093
0 commit comments