Imported Upstream version 1.18.0
[platform/core/ml/nnfw.git] / runtime / libs / ndarray / src / detail / cxx14.h
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef _NDARRAY_CXX14_H_
18 #define _NDARRAY_CXX14_H_
19
20 namespace ndarray
21 {
22
23 namespace cxx14
24 {
25
26 template <size_t... Nums> struct index_sequence
27 {
28   using value_type = size_t;
29
30   static constexpr std::size_t size() noexcept { return sizeof...(Nums); }
31 };
32
33 namespace detail
34 {
35
36 template <size_t v, typename Seq> struct _append;
37
38 template <size_t v, size_t... Nums> struct _append<v, index_sequence<Nums...>>
39 {
40   using result = index_sequence<Nums..., v>;
41 };
42
43 template <size_t Len> struct make_index_sequence
44 {
45   using result =
46     typename detail::_append<Len - 1, typename make_index_sequence<Len - 1>::result>::result;
47 };
48
49 template <> struct make_index_sequence<1>
50 {
51   using result = index_sequence<0>;
52 };
53
54 template <> struct make_index_sequence<0>
55 {
56   using result = index_sequence<>;
57 };
58
59 } // namespace detail
60
61 template <size_t Num> using make_index_sequence = typename detail::make_index_sequence<Num>::result;
62
63 } // namespace cxx14
64
65 } // namespace ndarray
66
67 #endif //_NDARRAY_CXX14_H_