chromium/base/types/variant_util.h

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_TYPES_VARIANT_UTIL_H_
#define BASE_TYPES_VARIANT_UTIL_H_

#include <stddef.h>

#include <type_traits>

#include "base/types/always_false.h"
#include "third_party/abseil-cpp/absl/types/variant.h"

namespace base {
namespace internal {

template <typename Variant, typename T>
struct VariantIndexOfTypeHelper {};

VariantIndexOfTypeHelper<absl::variant<Ts...>, T>;

}  // namespace internal

// Returns the 0-based index of `T` in `Variant`'s list of alternative types,
// e.g. given `Variant` == `absl::variant<A, B, C>` and `T` == `B`, returns 1.
//
// Note that this helper cannot be used if the list of alternative types
// contains duplicates.
template <typename Variant, typename T>
constexpr size_t VariantIndexOfType() {}

}  // namespace base

#endif  // BASE_TYPES_VARIANT_UTIL_H_