-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added comms::util::construct() functions.
- Loading branch information
Showing
7 changed files
with
119 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// Copyright 2024 - 2024 (C). Alex Robenko. All rights reserved. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
/// @file | ||
/// @brief Provides helper construct() function to allow easy construction of various collection types. | ||
|
||
#pragma once | ||
|
||
#include "comms/util/details/ConstructHelper.h" | ||
|
||
namespace comms | ||
{ | ||
|
||
namespace util | ||
{ | ||
|
||
/// @brief Construct collection objects given two range iterators | ||
/// @details The function selects proper constructor of the selected type | ||
/// @param[in] from Iterator to the first element of the range | ||
/// @param[in] to Iterator to one behind the last element of the range. | ||
template <typename T, typename TIter> | ||
T construct(TIter from, TIter to) | ||
{ | ||
return details::ConstructHelper<T>::construct(from, to); | ||
} | ||
|
||
} // namespace util | ||
|
||
} // namespace comms | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// Copyright 2024 - 2024 (C). Alex Robenko. All rights reserved. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
#include "comms/CompileControl.h" | ||
|
||
#include <iterator> | ||
|
||
#if COMMS_HAS_CPP20_SPAN | ||
#include <span> | ||
#endif // #if COMMS_HAS_CPP20_SPAN | ||
|
||
namespace comms | ||
{ | ||
|
||
namespace util | ||
{ | ||
|
||
namespace details | ||
{ | ||
|
||
template <typename T> | ||
class ConstructHelper | ||
{ | ||
public: | ||
using RetType = T; | ||
|
||
template <typename TIter> | ||
static RetType construct(TIter from, TIter to) | ||
{ | ||
return RetType(from, to); | ||
} | ||
}; | ||
|
||
#if COMMS_HAS_CPP20_SPAN | ||
template <typename T, std::size_t TExtent> | ||
class ConstructHelper<std::span<T, TExtent>> | ||
{ | ||
public: | ||
using RetType = std::span<T, TExtent>; | ||
|
||
template <typename TIter> | ||
static RetType construct(TIter from, TIter to) | ||
{ | ||
return RetType(&(*from), static_cast<typename RetType::size_type>(std::distance(from, to))); | ||
} | ||
}; | ||
#endif // #if COMMS_HAS_CPP20_SPAN | ||
|
||
} // namespace details | ||
|
||
} // namespace util | ||
|
||
} // namespace comms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters