OpenShaderDesigner 0.0.1
Loading...
Searching...
No Matches
Any.h
1// =====================================================================================================================
2// Copyright 2024 Medusa Slockbower
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// =====================================================================================================================
15
16#ifndef ANY_H
17#define ANY_H
18
20
21template<typename...Ts> class Any;
22
26template<typename T, typename...Rest>
27class Any<T, Rest...> : public Any<Rest...>
28{
29 // Ensure each element is unique
30 static_assert(IsUnique<Rest...>);
31 using ThisType = T;
32 using BaseType = Any<Rest...>;
33
34public:
35 Any() : BaseType() , Value() { }
36 Any(const ThisType& value, const Rest&...other) : BaseType(other...), Value(value) { }
37 Any(ThisType&& value, Rest&&...other) : BaseType(other...), Value(value) { }
38 Any(const Any& other) = default;
39 Any(Any&& other) = default;
40 ~Any() = default;
41
42 Any& operator=(const Any&) = default;
43 Any& operator=(Any&&) = default;
44
45 operator ThisType () const { return Value; }
46 operator ThisType& () { return Value; }
47 operator const ThisType& () const { return Value; }
48 operator ThisType&&() { return Value; }
49 operator ThisType* () { return &Value; }
50 operator const ThisType* () const { return &Value; }
51
52private:
53 static constexpr size_t Size = sizeof...(Rest);
54 ThisType Value;
55};
56
57template<>
58class Any<> { };
59
60#endif //ANY_H
Provides compile time evaluation utilities for templates and template packs.
Definition Any.h:21