ClickHouse/src/Functions/castTypeToEither.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
695 B
C++
Raw Normal View History

#pragma once
#include <Common/typeid_cast.h>
2021-11-25 20:55:02 +00:00
#include <base/TypeList.h>
namespace DB
{
template <typename... Ts, typename T, typename F>
static bool castTypeToEither(const T * type, F && f)
{
/// XXX can't use && here because gcc-7 complains about parentheses around && within ||
return ((typeid_cast<const Ts *>(type) ? f(*typeid_cast<const Ts *>(type)) : false) || ...);
}
template <class ...Args>
2021-11-25 20:55:02 +00:00
constexpr bool castTypeToEither(TypeList<Args...>, const auto * type, auto && f)
{
return (
(typeid_cast<const Args *>(type) != nullptr
? std::forward<decltype(f)>(f)(
*typeid_cast<const Args *>(type))
: false)
|| ...);
}
}