AUI Framework  master
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
variant.h
    1/*
    2 * AUI Framework - Declarative UI toolkit for modern C++20
    3 * Copyright (C) 2020-2025 Alex2772 and Contributors
    4 *
    5 * SPDX-License-Identifier: MPL-2.0
    6 *
    7 * This Source Code Form is subject to the terms of the Mozilla Public
    8 * License, v. 2.0. If a copy of the MPL was not distributed with this
    9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
   10 */
   11
   12#pragma once
   13
   14#include <cstdint>
   15#include <type_traits>
   16
   17namespace aui::variant {
   18
   23template<typename Variant, typename Type>
   25private:
   26    template<std::size_t i, std::size_t... next>
   27    static constexpr std::size_t value_impl2(std::index_sequence<i, next...>) {
   28        if constexpr (std::is_same_v<std::variant_alternative_t<i, Variant>, Type>) {
   29            return i;
   30        } else {
   31            return value_impl2(std::index_sequence<next...>{});
   32        }
   33    }
   34
   35    static constexpr std::size_t value_impl() {
   36        return value_impl2(std::make_index_sequence<std::variant_size_v<Variant>>());
   37    }
   38public:
   39    static constexpr std::size_t value = value_impl();
   40};
   41}
Determines type index inside of std::variant.
Definition variant.h:24