Skip to content

Commit

Permalink
Lighter header for forward-declared optional_traits.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
vector-of-bool committed Apr 8, 2024
1 parent 15771e0 commit 8ef8ba1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 37 deletions.
4 changes: 1 addition & 3 deletions src/neo/optional.detail.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#pragma once

#include <neo/concepts.hpp>
#include <neo/optional_traits.hpp>
#include <neo/type_traits.hpp>

#include <optional>

namespace neo {

template <typename T>
struct optional_traits;

template <typename T>
class optional;

Expand Down
34 changes: 0 additions & 34 deletions src/neo/optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,40 +449,6 @@ struct default_optional_state {
default_optional_state() = default;
};

/**
* @brief Specialize to customize the implementation of neo::optional
*
* @tparam T The type for which we are specializing
*
* A valid specialization of optional_traits defines the following:
*
* - `typename state_type` must be a type that is default-constructible. A default-constructed
* state_type object MUST represent an unalive "disengaged" state. The optional<T>
* will inherit its copy/move/assign/destruct attributes from the state_type object,
* i.e. whether it is trivial, copyable, constexpr, noexcept, etc.
* - static has_value(const state_type&) noexcept -> bool
* - Must return `true` if the state is alive, otherwise `false`
* - static get(state_type [const] &) -> T [const] &
* - Obtain a reference to the managed value. Should propagate cv
* qualifiers correctly for the underlying type. May assume that the
* state is alive.
* - static destroy(state_type&) -> void
* - Should clear the live value in the state and reset to null. May assume
* that the state is alive.
* - static construct(state_type&, ...)
* - Should construct a new live value from the given arguments. May assume
* that the state is dead.
* - static copy(state_type& into, state_type [const] [ref] from)
* - Should copy/move construct from live state `from` into disengaged
* state `into`
* - static assign(state_type& into, state_type [const] [ref] from)
* - Should copy/move assign from live state `from` into live state `into`
*
* - static constexpr bool trivial_move • Allow trivial moves of the state
* - static constexpr bool trivial_move_assign • Allow trivial move-assignment of the state
* - static constexpr bool trivial_copy • Allow trivial copy of the state
* - static constexpr bool trivial_copy_assign • Allow trivial copy-assignment of the state
*/
template <typename T>
struct optional_traits {
using state_type = default_optional_state<T>;
Expand Down
42 changes: 42 additions & 0 deletions src/neo/optional_traits.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

namespace neo {

/**
* @brief Specialize to customize the implementation of neo::optional
*
* @tparam T The type for which we are specializing
*
* A valid specialization of optional_traits defines the following:
*
* - `typename state_type` must be a type that is default-constructible. A default-constructed
* state_type object MUST represent an unalive "disengaged" state. The optional<T>
* will inherit its copy/move/assign/destruct attributes from the state_type object,
* i.e. whether it is trivial, copyable, constexpr, noexcept, etc.
* - static has_value(const state_type&) noexcept -> bool
* - Must return `true` if the state is alive, otherwise `false`
* - static get(state_type [const] &) -> T [const] &
* - Obtain a reference to the managed value. Should propagate cv
* qualifiers correctly for the underlying type. May assume that the
* state is alive.
* - static destroy(state_type&) -> void
* - Should clear the live value in the state and reset to null. May assume
* that the state is alive.
* - static construct(state_type&, ...)
* - Should construct a new live value from the given arguments. May assume
* that the state is dead.
* - static copy(state_type& into, state_type [const] [ref] from)
* - Should copy/move construct from live state `from` into disengaged
* state `into`
* - static assign(state_type& into, state_type [const] [ref] from)
* - Should copy/move assign from live state `from` into live state `into`
*
* - static constexpr bool trivial_move • Allow trivial moves of the state
* - static constexpr bool trivial_move_assign • Allow trivial move-assignment of the state
* - static constexpr bool trivial_copy • Allow trivial copy of the state
* - static constexpr bool trivial_copy_assign • Allow trivial copy-assignment of the state
*/
template <typename T>
struct optional_traits;

} // namespace neo

0 comments on commit 8ef8ba1

Please sign in to comment.