VCTR
Loading...
Searching...
No Matches
TransformedByDynamicCast.h
1/*
2 ==============================================================================
3 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
5 Copyright 2025 by sonible GmbH.
6
7 This file is part of VCTR - Versatile Container Templates Reconceptualized.
8
9 VCTR is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License version 3
11 only, as published by the Free Software Foundation.
12
13 VCTR is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License version 3 for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 version 3 along with VCTR. If not, see <https://www.gnu.org/licenses/>.
20 ==============================================================================
21*/
22
23namespace vctr::expressions
24{
25
26template <class T>
28
29template <size_t extent, class SrcType, isRefOrPtr DstValueType, is::constant ExpectCastToSucceed>
31{
32public:
33 using value_type = DstValueType;
34
35 VCTR_COMMON_UNARY_EXPRESSION_MEMBERS (TransformedByDynamicCast, src)
36
37 VCTR_FORCEDINLINE constexpr DstValueType operator[] (size_t i) const
38 {
39 DstValueType casted = dynamic_cast<DstValueType> (src[i]);
40
41 if constexpr (is::pointer<ValueType<SrcType>> && ExpectCastToSucceed::value)
42 VCTR_ASSERT (casted != nullptr);
43
44 return casted;
45 }
46};
47
48} // namespace vctr::expressions
49
50namespace vctr
51{
59template <class DstType, bool expectCastToSucceed = true>
61
62} // namespace vctr
63
Definition: TransformedByDynamicCast.h:31
Definition: TransformedByDynamicCast.h:27
Constrains a type to be an lvalue reference.
Definition: GenericConcepts.h:98
Constrains a type to be a pointer or a reference to a pointer.
Definition: GenericConcepts.h:86
constexpr ExpressionChainBuilder< expressions::TransformedByDynamicCast, DstType, Constant< expectCastToSucceed > > transformedByDynamicCastTo
Transforms all source elements to DstValueType by applying a dynamic_cast<DstValueType> to them.
Definition: TransformedByDynamicCast.h:60
The main namespace of the VCTR project.
Definition: Array.h:24
An expression chain builder is an object which supplies various operator<< overloads which build chai...
Definition: ExpressionChainBuilder.h:157
The base class to every expression template.
Definition: ExpressionTemplate.h:37