typeidx: add variant query
This commit is contained in:
parent
8bfb1e3d92
commit
c6912618a4
18
typeidx.hpp
18
typeidx.hpp
@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <variant>
|
||||
|
||||
|
||||
namespace cruft {
|
||||
@ -49,4 +50,21 @@ namespace cruft {
|
||||
static auto id = detail::typeidx_next<TagT> ();
|
||||
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 <typename TagT=void, typename ...ComponentT>
|
||||
int
|
||||
value_typeidx (std::variant<ComponentT...> const &val)
|
||||
{
|
||||
return std::visit (
|
||||
[] <typename ValueT> (ValueT const &) {
|
||||
return typeidx<ValueT> ();
|
||||
},
|
||||
val
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user