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