Fast CDR  Version 2.2.6
Fast CDR
Loading...
Searching...
No Matches
optional.hpp
1// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15#ifndef _FASTCDR_XCDR_DETAIL_OPTIONAL_HPP_
16#define _FASTCDR_XCDR_DETAIL_OPTIONAL_HPP_
17
18#include <type_traits>
19
20namespace eprosima {
21namespace fastcdr {
22namespace detail {
23template<class T, typename = void>
25{
26 union
27 {
28 char dummy_;
30 };
31
32 bool engaged_ { false };
33
35 {
36 }
37
39 {
40 if (engaged_)
41 {
42 val_.~T();
43 }
44 }
45
46};
47
48/* *INDENT-OFF* */
49template<class T>
50struct optional_storage<T, typename std::enable_if<std::is_trivially_destructible<T>::value>::type>
51{
52 union
53 {
54 char dummy_; T val_;
55 };
56
57 bool engaged_ { false };
58
60 {
61 }
62
63 ~optional_storage() = default;
64};
65/* *INDENT-ON* */
66} // namespace detail
67} // namespace fastcdr
68} // namespace eprosima
69
70#endif //_FASTCDR_XCDR_DETAIL_OPTIONAL_HPP_
71
Definition Cdr.h:49
char dummy_
Definition optional.hpp:28
bool engaged_
Definition optional.hpp:32
~optional_storage()
Definition optional.hpp:38
optional_storage()
Definition optional.hpp:34