2015-10-12 07:05:54 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/Field.h>
|
2015-10-12 07:05:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-01-06 17:41:19 +00:00
|
|
|
/** StaticVisitor (and its descendants) - class with overloaded operator() for all types of fields.
|
|
|
|
* You could call visitor for field using function 'applyVisitor'.
|
|
|
|
* Also "binary visitor" is supported - its operator() takes two arguments.
|
2015-10-12 07:05:54 +00:00
|
|
|
*/
|
|
|
|
template <typename R = void>
|
|
|
|
struct StaticVisitor
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
using ResultType = R;
|
2015-10-12 07:05:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-01-06 17:41:19 +00:00
|
|
|
/// F is template parameter, to allow universal reference for field, that is useful for const and non-const values.
|
2015-10-12 07:05:54 +00:00
|
|
|
template <typename Visitor, typename F>
|
2019-12-10 13:40:45 +00:00
|
|
|
auto applyVisitor(Visitor && visitor, F && field)
|
2015-10-12 07:05:54 +00:00
|
|
|
{
|
2020-07-09 16:15:46 +00:00
|
|
|
return Field::dispatch(std::forward<Visitor>(visitor),
|
|
|
|
std::forward<F>(field));
|
2015-10-12 07:05:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Visitor, typename F1, typename F2>
|
2019-12-10 13:40:45 +00:00
|
|
|
auto applyVisitor(Visitor && visitor, F1 && field1, F2 && field2)
|
2015-10-12 07:05:54 +00:00
|
|
|
{
|
2020-07-09 16:15:46 +00:00
|
|
|
return Field::dispatch(
|
2020-07-10 05:37:43 +00:00
|
|
|
[&field2, &visitor](auto & field1_value)
|
2019-12-10 13:40:45 +00:00
|
|
|
{
|
2020-07-09 16:15:46 +00:00
|
|
|
return Field::dispatch(
|
|
|
|
[&field1_value, &visitor](auto & field2_value)
|
2019-12-10 13:40:45 +00:00
|
|
|
{
|
|
|
|
return visitor(field1_value, field2_value);
|
|
|
|
},
|
2020-07-09 16:15:46 +00:00
|
|
|
std::forward<F2>(field2));
|
2019-12-10 13:40:45 +00:00
|
|
|
},
|
2020-07-09 16:15:46 +00:00
|
|
|
std::forward<F1>(field1));
|
2015-10-12 07:05:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|