COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
ConstructHelper.h
1//
2// Copyright 2024 - 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
13
14#include <cstddef>
15#include <iterator>
16
17#if COMMS_HAS_CPP20_SPAN
18#include <span>
19#endif // #if COMMS_HAS_CPP20_SPAN
20
21namespace comms
22{
23
24namespace util
25{
26
27namespace details
28{
29
30template <typename T>
31class ConstructHelper
32{
33public:
34 using RetType = T;
35
36 template <typename TIter>
37 static RetType construct(TIter from, TIter to)
38 {
39 return RetType(from, to);
40 }
41};
42
43#if COMMS_HAS_CPP20_SPAN
44template <typename T, std::size_t TExtent>
45class ConstructHelper<std::span<T, TExtent>>
46{
47public:
48 using RetType = std::span<T, TExtent>;
49
50 template <typename TIter>
51 static RetType construct(TIter from, TIter to)
52 {
53 return RetType(&(*from), static_cast<typename RetType::size_type>(std::distance(from, to)));
54 }
55};
56#endif // #if COMMS_HAS_CPP20_SPAN
57
58} // namespace details
59
60} // namespace util
61
62} // namespace comms
Contains various compiler related definitions.
T construct(TIter from, TIter to)
Construct collection objects given two range iterators.
Definition construct.h:28
Main namespace for all classes / functions of COMMS library.
STL namespace.