Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
d29a8fc0
"src/git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "429e5449c12fa66ca489702e0a90900af415498c"
Commit
d29a8fc0
authored
Oct 28, 2021
by
Davis King
Browse files
Just minor cleanup of docs and renamed some stuff, tweaked formatting.
parent
2b8f9e40
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
30 deletions
+43
-30
dlib/type_safe_union/type_safe_union_kernel.h
dlib/type_safe_union/type_safe_union_kernel.h
+34
-22
dlib/type_safe_union/type_safe_union_kernel_abstract.h
dlib/type_safe_union/type_safe_union_kernel_abstract.h
+9
-8
No files found.
dlib/type_safe_union/type_safe_union_kernel.h
View file @
d29a8fc0
...
@@ -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
)
...
@@ -694,4 +706,4 @@ namespace dlib
...
@@ -694,4 +706,4 @@ namespace dlib
}
}
}
}
#endif // DLIB_TYPE_SAFE_UNIOn_h_
#endif // DLIB_TYPE_SAFE_UNIOn_h_
\ No newline at end of file
dlib/type_safe_union/type_safe_union_kernel_abstract.h
View file @
d29a8fc0
...
@@ -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
);
);
/*!
/*!
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment