Add support for function types

This commit is contained in:
Jonathan Müller 2017-02-23 14:36:37 +01:00
commit 8bb6268626
4 changed files with 95 additions and 44 deletions

View file

@ -11,23 +11,6 @@ namespace cppast
{
enum class cpp_entity_kind;
/// \exclude
namespace detail
{
void check_entity_cast_impl(const cpp_entity& e, cpp_entity_kind expected_kind);
template <typename T>
void check_entity_cast(const cpp_entity& e)
{
check_entity_cast_impl(e, T::kind());
}
template <>
inline void check_entity_cast<cpp_entity>(const cpp_entity&)
{
}
} // namespace detail
/// A basic reference to some kind of [cppast::cpp_entity]().
template <typename T, typename Predicate>
class basic_cpp_entity_ref
@ -57,7 +40,8 @@ namespace cppast
auto entity = idx.lookup(target_);
if (!entity)
return type_safe::nullopt;
detail::check_entity_cast<T>(entity.value());
DEBUG_ASSERT(Predicate{}(entity.value()), detail::precondition_error_handler{},
"predicate not fulfilled");
return static_cast<const T&>(entity.value());
}