19#include "comms/details/tag.h"
34 template <
typename T,
typename TIter>
35 static void assign(T& obj, TIter from, TIter to)
37 using ObjType =
typename std::decay<
decltype(obj)>::type;
38 static_assert(!std::is_same<Tag<ObjType>, UnknownTag<> >::value,
"Assignment to provided type is not supported");
39 assignInternal(obj, from, to, Tag<ObjType>());
43 template <
typename... TParams>
44 using UseAssignTag = comms::details::tag::Tag1<>;
46 template <
typename... TParams>
47 using UsePtrSizeConstructorTag = comms::details::tag::Tag2<>;
49 template <
typename... TParams>
50 using StdSpanTag = comms::details::tag::Tag3<>;
52 template <
typename... TParams>
53 using UnknownTag = comms::details::tag::Tag4<>;
56 using ConstructorTag =
57 typename comms::util::LazyShallowConditional<
58 comms::util::detect::hasPtrSizeConstructor<T>()
60 UsePtrSizeConstructorTag,
65 using SpanConstructorTag =
66 typename comms::util::LazyShallowConditional<
67 comms::util::detect::details::IsStdSpan<T>::Value
76 typename comms::util::LazyShallowConditional<
77 comms::util::detect::hasAssignFunc<T>()
84 template <
typename T,
typename TIter,
typename... TParams>
85 static void assignInternal(T& obj, TIter from, TIter to, UseAssignTag<TParams...>)
90 template <
typename T,
typename TIter,
typename... TParams>
91 static void assignInternal(T& obj, TIter from, TIter to, UsePtrSizeConstructorTag<TParams...>)
93 using IterType =
typename std::decay<TIter>::type;
94 using IterTag =
typename std::iterator_traits<IterType>::iterator_category;
95 static_assert(std::is_base_of<std::random_access_iterator_tag, IterTag>::value,
96 "Only random access iterator is supported for provided type assignments");
98 auto diff = std::distance(from, to);
100 static constexpr bool Invalid_iterators_used_for_assignment =
false;
101 static_cast<void>(Invalid_iterators_used_for_assignment);
106 using ObjType =
typename std::decay<
decltype(obj)>::type;
107 obj = ObjType(&(*from),
static_cast<std::size_t
>(diff));
110 template <
typename T,
typename TIter,
typename... TParams>
111 static void assignInternal(T& obj, TIter from, TIter to, StdSpanTag<TParams...>)
113 using ObjType =
typename std::decay<
decltype(obj)>::type;
114 using ConstPointerType =
typename ObjType::const_pointer;
115 using PointerType =
typename ObjType::pointer;
116 auto fromPtr =
const_cast<PointerType
>(
reinterpret_cast<ConstPointerType
>(&(*from)));
117 auto toPtr =
const_cast<PointerType
>(
reinterpret_cast<ConstPointerType
>(&(*to)));
118 assignInternal(obj, fromPtr, toPtr, UsePtrSizeConstructorTag<TParams...>());
This file contains classes required for generic custom assertion functionality.
#define COMMS_ASSERT(expr)
Generic assert macro.
Definition Assert.h:170
void assign(T &obj, TIter from, TIter to)
Assigns a new value to provided object.
Definition assign.h:39
Main namespace for all classes / functions of COMMS library.
Replacement to some types from standard type_traits.
Various compile-time detection functions of whether specific member functions and/or types exist.