From 693d5ba1904985c92c5218a19d16eb90ae7546dd Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Tue, 19 Jan 2021 16:40:59 +1100 Subject: [PATCH] Added utils::variant_index --- src/utils/variant.hpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/utils/variant.hpp b/src/utils/variant.hpp index 8c4fb5a3d51a..7a247e7fa7de 100644 --- a/src/utils/variant.hpp +++ b/src/utils/variant.hpp @@ -1,14 +1,14 @@ /* - Copyright (C) 2021 by the Battle for Wesnoth Project https://www.wesnoth.org/ + Copyright (C) 2021 by the Battle for Wesnoth Project https://www.wesnoth.org/ - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY. - See the COPYING file for more details. + See the COPYING file for more details. */ #pragma once @@ -68,4 +68,15 @@ inline T* get_if(V* variant) } #endif + +template +std::size_t variant_index(const variant& var) +{ +#ifndef USING_BOOST_VARIANT + return var.index(); +#else + return var.which(); +#endif +} + } // namespace utils