Commit d29a8fc0 authored by Davis King's avatar Davis King
Browse files

Just minor cleanup of docs and renamed some stuff, tweaked formatting.

parent 2b8f9e40
...@@ -276,9 +276,12 @@ namespace dlib ...@@ -276,9 +276,12 @@ namespace dlib
type_identity = get_type_id<T>(); type_identity = get_type_id<T>();
} }
struct helper_forward struct assign_to
{ {
helper_forward(type_safe_union& me) : _me(me) {} /*!
This class assigns an object to `me` using std::forward.
!*/
assign_to(type_safe_union& me) : _me(me) {}
template<typename T> template<typename T>
void operator()(T&& x) void operator()(T&& x)
...@@ -298,9 +301,12 @@ namespace dlib ...@@ -298,9 +301,12 @@ namespace dlib
type_safe_union& _me; type_safe_union& _me;
}; };
struct helper_move struct move_to
{ {
helper_move(type_safe_union& me) : _me(me) {} /*!
This class move assigns an object to `me`.
!*/
move_to(type_safe_union& me) : _me(me) {}
template<typename T> template<typename T>
void operator()(T& x) void operator()(T& x)
...@@ -318,15 +324,21 @@ namespace dlib ...@@ -318,15 +324,21 @@ namespace dlib
type_safe_union& _me; type_safe_union& _me;
}; };
struct swap_helper struct swap_to
{ {
swap_helper(type_safe_union& me) : _me(me) {} /*!
This class swaps an object with `me`.
!*/
swap_to(type_safe_union& me) : _me(me) {}
template<typename T> template<typename T>
void operator()(T& x) void operator()(T& x)
/*!
requires
- _me.contains<T>() == true
!*/
{ {
using std::swap; using std::swap;
swap(_me.unchecked_get<T>(), x); //really you want to use cast_to<T>(), BUT, swap is supposed to be nothrow swap(_me.unchecked_get<T>(), x);
} }
type_safe_union& _me; type_safe_union& _me;
...@@ -340,7 +352,7 @@ namespace dlib ...@@ -340,7 +352,7 @@ namespace dlib
const type_safe_union& item const type_safe_union& item
) : type_safe_union() ) : type_safe_union()
{ {
item.visit(helper_forward{*this}); item.visit(assign_to{*this});
} }
type_safe_union& operator=( type_safe_union& operator=(
...@@ -350,7 +362,7 @@ namespace dlib ...@@ -350,7 +362,7 @@ namespace dlib
if (item.is_empty()) if (item.is_empty())
destruct(); destruct();
else else
item.visit(helper_forward{*this}); item.visit(assign_to{*this});
return *this; return *this;
} }
...@@ -358,7 +370,7 @@ namespace dlib ...@@ -358,7 +370,7 @@ namespace dlib
type_safe_union&& item type_safe_union&& item
) : type_safe_union() ) : type_safe_union()
{ {
item.visit(helper_move{*this}); item.visit(move_to{*this});
item.destruct(); item.destruct();
} }
...@@ -372,7 +384,7 @@ namespace dlib ...@@ -372,7 +384,7 @@ namespace dlib
} }
else else
{ {
item.visit(helper_move{*this}); item.visit(move_to{*this});
item.destruct(); item.destruct();
} }
return *this; return *this;
...@@ -386,7 +398,7 @@ namespace dlib ...@@ -386,7 +398,7 @@ namespace dlib
T&& item T&& item
) : type_safe_union() ) : type_safe_union()
{ {
helper_forward{*this}(std::forward<T>(item)); assign_to{*this}(std::forward<T>(item));
} }
template < template <
...@@ -397,7 +409,7 @@ namespace dlib ...@@ -397,7 +409,7 @@ namespace dlib
T&& item T&& item
) )
{ {
helper_forward{*this}(std::forward<T>(item)); assign_to{*this}(std::forward<T>(item));
return *this; return *this;
} }
...@@ -492,16 +504,16 @@ namespace dlib ...@@ -492,16 +504,16 @@ namespace dlib
{ {
if (type_identity == item.type_identity) if (type_identity == item.type_identity)
{ {
item.visit(swap_helper{*this}); item.visit(swap_to{*this});
} }
else if (is_empty()) else if (is_empty())
{ {
item.visit(helper_move{*this}); item.visit(move_to{*this});
item.destruct(); item.destruct();
} }
else if (item.is_empty()) else if (item.is_empty())
{ {
visit(helper_move{item}); visit(move_to{item});
destruct(); destruct();
} }
else else
...@@ -606,7 +618,7 @@ namespace dlib ...@@ -606,7 +618,7 @@ namespace dlib
deserialize_helper<I+1>(in, index, x); deserialize_helper<I+1>(in, index, x);
} }
} }
} } // namespace detail
template<typename... Types> template<typename... Types>
inline void serialize ( inline void serialize (
...@@ -649,7 +661,7 @@ namespace dlib ...@@ -649,7 +661,7 @@ namespace dlib
} }
} }
#if __cplusplus >= 201703L #if __cplusplus >= 201703L
template<typename ...Base> template<typename ...Base>
struct overloaded_helper : Base... struct overloaded_helper : Base...
...@@ -660,7 +672,7 @@ namespace dlib ...@@ -660,7 +672,7 @@ namespace dlib
using Base::operator()...; using Base::operator()...;
}; };
#else #else
template<typename Base, typename ... BaseRest> template<typename Base, typename ... BaseRest>
struct overloaded_helper: Base, overloaded_helper<BaseRest...> struct overloaded_helper: Base, overloaded_helper<BaseRest...>
...@@ -685,7 +697,7 @@ namespace dlib ...@@ -685,7 +697,7 @@ namespace dlib
using Base::operator(); using Base::operator();
}; };
#endif //__cplusplus >= 201703L #endif //__cplusplus >= 201703L
template<typename... T> template<typename... T>
overloaded_helper<typename std::decay<T>::type...> overloaded(T&&... t) overloaded_helper<typename std::decay<T>::type...> overloaded(T&&... t)
......
...@@ -39,6 +39,7 @@ namespace dlib ...@@ -39,6 +39,7 @@ namespace dlib
tsu a(in_place_tag<A>{}, 0, 1); tsu a(in_place_tag<A>{}, 0, 1);
!*/ !*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template <typename... Types> template <typename... Types>
...@@ -74,7 +75,7 @@ namespace dlib ...@@ -74,7 +75,7 @@ namespace dlib
) = default; ) = default;
/*! /*!
ensures ensures
- this object is properly initialized - #is_empty() == true
!*/ !*/
type_safe_union ( type_safe_union (
...@@ -335,10 +336,10 @@ namespace dlib ...@@ -335,10 +336,10 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template < ... > template<typename... Types>
inline void swap ( inline void swap (
type_safe_union<...>& a, type_safe_union<Types...>& a,
type_safe_union<...>& b type_safe_union<Types...>& b
) { a.swap(b); } ) { a.swap(b); }
/*! /*!
provides a global swap function provides a global swap function
...@@ -346,9 +347,9 @@ namespace dlib ...@@ -346,9 +347,9 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template < ... > template<typename... Types>
void serialize ( void serialize (
const type_safe_union<...>& item, const type_safe_union<Types...>& item,
std::ostream& out std::ostream& out
); );
/*! /*!
...@@ -362,9 +363,9 @@ namespace dlib ...@@ -362,9 +363,9 @@ namespace dlib
serialize(item.get<type_of_object_in_item>(), out); serialize(item.get<type_of_object_in_item>(), out);
!*/ !*/
template < ... > template<typename... Types>
void deserialize ( void deserialize (
type_safe_union<...>& item, type_safe_union<Types...>& item,
std::istream& in std::istream& in
); );
/*! /*!
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment