Skip to content

Commit

Permalink
Added utils::variant_index
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Jan 19, 2021
1 parent 25bebba commit 693d5ba
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions 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
Expand Down Expand Up @@ -68,4 +68,15 @@ inline T* get_if(V* variant)
}

#endif

template<typename... Types>
std::size_t variant_index(const variant<Types...>& var)
{
#ifndef USING_BOOST_VARIANT
return var.index();
#else
return var.which();
#endif
}

} // namespace utils

0 comments on commit 693d5ba

Please sign in to comment.