chromium/v8/src/base/template-meta-programming/string-literal.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_STRING_LITERAL_H_
#define V8_BASE_TEMPLATE_META_PROGRAMMING_STRING_LITERAL_H_

#include <algorithm>

#include "src/base/compiler-specific.h"
#include "src/base/logging.h"

namespace v8::base::tmp {

#ifdef HAS_CPP_CLASS_TYPES_AS_TEMPLATE_ARGS

#ifdef __cpp_lib_to_array
to_array;
#else
namespace detail {
template <typename T, size_t N, size_t... I>
constexpr std::array<std::remove_cv_t<T>, N> to_array_impl(
    T (&a)[N], std::index_sequence<I...>) {
  return {{a[I]...}};
}
}  // namespace detail
template <typename T, size_t N>
constexpr std::array<std::remove_cv_t<T>, N> to_array(T (&a)[N]) {
  return detail::to_array_impl(a, std::make_index_sequence<N>{});
}
#endif

// This class provides a way to pass compile time string literals to templates
// using extended non-type template parameters.
template <size_t N>
class StringLiteral {};

// Deduction guide for `StringLiteral`.
template <size_t N>
StringLiteral(const char (&)[N]) -> StringLiteral<N>;

#endif

}  // namespace v8::base::tmp

#endif  // V8_BASE_TEMPLATE_META_PROGRAMMING_STRING_LITERAL_H_