/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Copyright 2017 Danny Robson */ #ifndef CRUFT_UTIL_TYPEIDX_HPP #define CRUFT_UTIL_TYPEIDX_HPP #include namespace util { namespace detail { int typeidx_next (void); } /// return a globally unique runtime ID for a given type. /// /// this is intended to be used as a lightweight type check for variants /// and such without requiring RTTI. /// /// the identifier is constructed at runtime and is not guaranteed to be /// stable across executions (particularly in the case of threads and /// other non-determinism). however it _is_ threadsafe to call this. /// /// the range of identifiers is _probably_ contiguous starting from zero. /// this should not be relied upon for correctness, but may be used for /// performance concerns. template int typeidx (void) { static auto id = detail::typeidx_next (); return id; } } #endif