chromium/v8/src/base/template-meta-programming/list.h

// Copyright 2024 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_BASE_TEMPLATE_META_PROGRAMMING_LIST_H_
#define V8_BASE_TEMPLATE_META_PROGRAMMING_LIST_H_

#include <type_traits>

namespace v8::base::tmp {

template <typename...>
struct list {};

namespace detail {

template <typename List>
struct length_impl;
length_impl<list<Ts...>>;

template <typename List, int Index>
struct element_impl;
element_impl<list<Head, Tail...>, 0>;
element_impl<list<Head, Tail...>, Index>;

}  // namespace detail

// length<List>::value is the length of the {List}.
template <typename List>
struct length : detail::length_impl<List> {};
length_v;

// element<List, Index>::type is the {List}'s element at {Index}.
template <typename List, int Index>
struct element : detail::element_impl<List, Index> {};
element_t;

}  // namespace v8::base::tmp

#endif  // V8_BASE_TEMPLATE_META_PROGRAMMING_LIST_H_