iceoryx_hoofs  2.0.2
newtype.hpp
1 // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
2 // Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 // SPDX-License-Identifier: Apache-2.0
17 #ifndef IOX_HOOFS_CXX_NEWTYPE_HPP
18 #define IOX_HOOFS_CXX_NEWTYPE_HPP
19 
20 #include "iceoryx_hoofs/cxx/algorithm.hpp"
21 #include "iceoryx_hoofs/internal/cxx/newtype/assignment.hpp"
22 #include "iceoryx_hoofs/internal/cxx/newtype/comparable.hpp"
23 #include "iceoryx_hoofs/internal/cxx/newtype/constructor.hpp"
24 #include "iceoryx_hoofs/internal/cxx/newtype/convertable.hpp"
25 #include "iceoryx_hoofs/internal/cxx/newtype/internal.hpp"
26 #include "iceoryx_hoofs/internal/cxx/newtype/protected_constructor.hpp"
27 #include "iceoryx_hoofs/internal/cxx/newtype/sortable.hpp"
28 
29 #include <type_traits>
30 
31 namespace iox
32 {
33 namespace cxx
34 {
72 template <typename T, template <typename> class... Policies>
73 class NewType : public Policies<NewType<T, Policies...>>...
74 {
75  protected:
76  NewType(newtype::internal::ProtectedConstructor_t, const T& rhs) noexcept;
77 
78  public:
80  using ThisType = NewType<T, Policies...>;
82  using value_type = T;
83 
85  NewType() noexcept;
86 
88  explicit NewType(const T& rhs) noexcept;
89 
91  NewType(const NewType& rhs) noexcept;
92 
94  NewType(NewType&& rhs) noexcept;
95 
97  NewType& operator=(const NewType& rhs) noexcept;
98 
100  NewType& operator=(NewType&& rhs) noexcept;
101 
103  NewType& operator=(const T& rhs) noexcept;
104 
106  NewType& operator=(T&& rhs) noexcept;
107 
109  explicit operator T() const noexcept;
110 
111  template <typename Type>
112  friend typename Type::value_type newtype::internal::newTypeAccessor(const Type&) noexcept;
113 
114  private:
115  T m_value;
116 };
117 } // namespace cxx
118 } // namespace iox
119 
120 #include "iceoryx_hoofs/internal/cxx/newtype.inl"
121 
122 #endif
Implementation of the haskell NewType pattern: https://wiki.haskell.org/Newtype Lets say you would li...
Definition: newtype.hpp:74
T value_type
the type of the underlying value
Definition: newtype.hpp:82
NewType() noexcept
default constructor
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:29