iceoryx_doc  1.0.1
newtype.hpp
1 // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
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 // SPDX-License-Identifier: Apache-2.0
16 #ifndef IOX_UTILS_CXX_NEWTYPE_HPP
17 #define IOX_UTILS_CXX_NEWTYPE_HPP
18 
19 #include "iceoryx_utils/cxx/algorithm.hpp"
20 #include "iceoryx_utils/internal/cxx/newtype/assignment.hpp"
21 #include "iceoryx_utils/internal/cxx/newtype/comparable.hpp"
22 #include "iceoryx_utils/internal/cxx/newtype/constructor.hpp"
23 #include "iceoryx_utils/internal/cxx/newtype/convertable.hpp"
24 #include "iceoryx_utils/internal/cxx/newtype/internal.hpp"
25 #include "iceoryx_utils/internal/cxx/newtype/protected_constructor.hpp"
26 #include "iceoryx_utils/internal/cxx/newtype/sortable.hpp"
27 
28 #include <type_traits>
29 
30 namespace iox
31 {
32 namespace cxx
33 {
63 template <typename T, template <typename> class... Policies>
64 class NewType : public Policies<NewType<T, Policies...>>...
65 {
66  protected:
67  NewType(newtype::internal::ProtectedConstructor_t, const T& rhs) noexcept;
68 
69  public:
71  using ThisType = NewType<T, Policies...>;
73  using value_type = T;
74 
76  NewType() noexcept;
77 
79  explicit NewType(const T& rhs) noexcept;
80 
82  NewType(const NewType& rhs) noexcept;
83 
85  NewType(NewType&& rhs) noexcept;
86 
88  NewType& operator=(const NewType& rhs) noexcept;
89 
91  NewType& operator=(NewType&& rhs) noexcept;
92 
94  NewType& operator=(const T& rhs) noexcept;
95 
97  NewType& operator=(T&& rhs) noexcept;
98 
100  explicit operator T() const noexcept;
101 
102  template <typename Type>
103  friend typename Type::value_type newtype::internal::newTypeAccessor(const Type&) noexcept;
104 
105  private:
106  T m_value;
107 };
108 } // namespace cxx
109 } // namespace iox
110 
111 #include "iceoryx_utils/internal/cxx/newtype.inl"
112 
113 #endif
Implementation of the haskell NewType pattern: https://wiki.haskell.org/Newtype Lets say you would li...
Definition: newtype.hpp:65
T value_type
the type of the underlying value
Definition: newtype.hpp:73
NewType() noexcept
default constructor
Definition: newtype.inl:24
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:28