diff --git a/typeidx.hpp b/typeidx.hpp index d2589062..5855173b 100644 --- a/typeidx.hpp +++ b/typeidx.hpp @@ -9,6 +9,7 @@ #pragma once #include +#include namespace cruft { @@ -49,4 +50,21 @@ namespace cruft { static auto id = detail::typeidx_next (); return id; } + + + /// Returns the typeidx of the contained value within a variant. + /// + /// May throw std::bad_variant_access if the variant is + /// valueless_by_exception. + template + int + value_typeidx (std::variant const &val) + { + return std::visit ( + [] (ValueT const &) { + return typeidx (); + }, + val + ); + } }