iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
into.hpp
Go to the documentation of this file.
1// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
2// Copyright (c) 2021 - 2023 by Apex.AI Inc. All rights reserved.
3// Copyright (c) 2025 Contributors to the Eclipse Foundation
4//
5// See the NOTICE file(s) distributed with this work for additional
6// information regarding copyright ownership.
7//
8// This program and the accompanying materials are made available under the
9// terms of the Apache Software License 2.0 which is available at
10// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
11// which is available at https://opensource.org/licenses/MIT.
12//
13// SPDX-License-Identifier: Apache-2.0 OR MIT
14
15#ifndef IOX2_BB_INTO_HPP
16#define IOX2_BB_INTO_HPP
17
20
21namespace iox2 {
22namespace bb {
23
25template <typename D>
26struct Lossy { };
27
28namespace detail {
31template <typename T>
33 using TargetType = T;
34};
35
37template <typename T>
39 using TargetType = T;
40};
41} // namespace detail
42
43// Using a struct as impl, as free functions do not support partially specialized templates
44template <typename SourceType, typename DestinationType>
45struct From {
46 // AXIVION Next Construct AutosarC++19_03-A7.1.5 : 'auto' is only used for the generic implementation which will always result in a compile error
47 static constexpr auto from(const SourceType& value IOX2_MAYBE_UNUSED) noexcept {
49Conversion for the specified types is not implemented!\n \
50Please specialize 'From::from'!\n \
51-------------------------------------------------------------------------\n \
52template <typename SourceType, typename DestinationType>\n \
53constexpr DestinationType From::from(const SourceType&) noexcept;\n \
54-------------------------------------------------------------------------");
55 }
56};
57
104template <typename SourceType, typename DestinationType>
105constexpr auto from(const SourceType value) noexcept -> typename detail::ExtractIntoType<DestinationType>::TargetType {
107}
108
119template <typename DestinationType, typename SourceType>
120constexpr auto into(const SourceType value) noexcept -> typename detail::ExtractIntoType<DestinationType>::TargetType {
121 return from<SourceType, DestinationType>(value);
122}
123
124} // namespace bb
125} // namespace iox2
126
127#endif // IOX2_BB_INTO_HPP
#define IOX2_MAYBE_UNUSED
IOX2_MAYBE_UNUSED adds the [[gnu::unused]] attribute when it is available for the current compiler or...
constexpr auto into(const SourceType value) noexcept -> typename detail::ExtractIntoType< DestinationType >::TargetType
Converts a value of type SourceType to a corresponding value of type DestinationType....
Definition into.hpp:120
constexpr auto from(const SourceType value) noexcept -> typename detail::ExtractIntoType< DestinationType >::TargetType
Converts a value of type SourceType to a corresponding value of type DestinationType....
Definition into.hpp:105
constexpr bool always_false_v
Helper value to bind a static_assert to a type.
static constexpr auto from(const SourceType &value IOX2_MAYBE_UNUSED) noexcept
Definition into.hpp:47
Helper struct to indicate a lossy conversion, e.g. from an unbounded type into a bounded type.
Definition into.hpp:26
Helper struct to get the actual destination type 'T' for 'into' with an additional indirection like '...
Definition into.hpp:32