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