forked from Tensor-Array/Tensor-Array
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitializer_wrapper.hh
More file actions
96 lines (81 loc) · 2.92 KB
/
initializer_wrapper.hh
File metadata and controls
96 lines (81 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
Copyright 2024 TensorArray-Creators
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <initializer_list>
namespace tensor_array
{
namespace wrapper
{
#ifdef _MSC_VER
template<class _E>
class initializer_wrapper: public std::initializer_list<_E>
{
public:
typedef _E value_type;
typedef const _E& reference;
typedef const _E& const_reference;
typedef size_t size_type;
typedef const _E* iterator;
typedef const _E* const_iterator;
public:
constexpr initializer_wrapper(const_iterator __a, size_type __l)
: std::initializer_list<_E>(__a, __a + __l) { }
constexpr initializer_wrapper(const_iterator __begin, const_iterator __end)
: std::initializer_list<_E>(__begin, __end) { }
constexpr initializer_wrapper() noexcept: std::initializer_list<_E>() { }
};
#else
template<class _E>
class initializer_wrapper
{
public:
typedef _E value_type;
typedef const _E& reference;
typedef const _E& const_reference;
typedef size_t size_type;
typedef const _E* iterator;
typedef const _E* const_iterator;
private:
#ifdef __GNUC__
iterator _M_array;
size_type _M_len;
#endif
public:
constexpr initializer_wrapper(const_iterator __a, size_type __l)
#ifdef __GNUC__
: _M_array(__a), _M_len(__l) { }
#endif
constexpr initializer_wrapper(const_iterator __begin, const_iterator __end)
: _M_array(__begin), _M_len(__end - __begin)
{ }
constexpr initializer_wrapper() noexcept: _M_array(0), _M_len(0) { }
// Number of elements.
constexpr size_type
size() const noexcept
{
return _M_len;
}
// First element.
constexpr const_iterator
begin() const noexcept {
return _M_array;
}
// One past the last element.
constexpr const_iterator
end() const noexcept {
return begin() + size();
}
constexpr operator std::initializer_list<_E>() const { return reinterpret_cast<const std::initializer_list<_E>&>(*this); }
};
#endif // !_MSC_VER
}
}