COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
ValueAssignWrapper.h
1//
2// Copyright 2019 - 2026 (C). Alex Robenko. All rights reserved.
3//
4// SPDX-License-Identifier: MPL-2.0
5//
6// This Source Code Form is subject to the terms of the Mozilla Public
7// License, v. 2.0. If a copy of the MPL was not distributed with this
8// file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10#pragma once
11
12#include <type_traits>
13
14namespace comms
15{
16
17namespace details
18{
19
20template <typename T>
21class ValueAssignWrapper
22{
23 using ValueType = typename std::decay<T>::type;
24
25public:
26 explicit ValueAssignWrapper(T& value) : m_value(value) {}
27
28 template <typename U>
29 ValueAssignWrapper& operator=(U&& val)
30 {
31 m_value = static_cast<ValueType>(val);
32 return *this;
33 }
34
35 operator ValueType&()
36 {
37 return m_value;
38 }
39
40 operator const ValueType&() const
41 {
42 return m_value;
43 }
44
45private:
46
47 T& m_value;
48};
49
50} // namespace details
51
52} // namespace comms
Main namespace for all classes / functions of COMMS library.