somewhat more generic detect_type utility
@@ -129,33 +129,49 @@ recognize_by_type_index(const U & object)
return nullptr;
}
-/** possible FastValue-specific utility */
-class Indexes {
+template<typename T, size_t N>
+class RecognizedValues
+{
private:
- const FastValueIndex *_a;
- const FastValueIndex *_b;
+ std::array<const T *, N> _pointers;
public:
- Indexes(const Value::Index &a_in, const Value::Index &b_in)
- : _a(recognize_by_type_index<FastValueIndex>(a_in)),
- _b(recognize_by_type_index<FastValueIndex>(b_in))
+ RecognizedValues(std::array<const T *, N> pointers)
+ : _pointers(std::move(pointers))
+ {}
+ bool all_converted() const {
+ for (auto p : _pointers) {
+ if (p == nullptr) return false;
+ }
+ return true;
+ }
+ operator bool() const { return all_converted(); }
+ template<size_t idx> const T& get() const {
+ static_assert(idx < N);
+ return *_pointers[idx];
+ }
+ const T& first() const { return get<0>(); }
+ const T& second() const { return get<1>(); }
+};
+
+template<typename T, typename... Args>
+RecognizedValues<T, sizeof...(Args)>
+detect_type(const Args &... args)
{
+ RecognizedValues<T, sizeof...(Args)> result({(recognize_by_type_index<T>(args))...});
+ return result;
}
- operator bool() const { return _a && _b; }
- const FastValueIndex &a() const { return *_a; }
- const FastValueIndex &b() const { return *_b; }
-};
template <typename LCT, typename RCT, typename OCT, typename Fun>
void my_sparse_merge_op(State &state, uint64_t param_in) {
const auto &param = unwrap_param<MergeParam>(param_in);
const Value &lhs = state.peek(1);
const Value &rhs = state.peek(0);
- if (auto indexes = Indexes(lhs.index(), rhs.index())) {
+ if (auto indexes = detect_type<FastValueIndex>(lhs.index(), rhs.index())) {
auto lhs_cells = lhs.cells().typify<LCT>();
auto rhs_cells = rhs.cells().typify<RCT>();
return state.pop_pop_push(
FastValueIndex::sparse_only_merge<LCT,RCT,OCT,Fun>(
- param.res_type, Fun(param.function), indexes.a(), indexes.b(), lhs_cells, rhs_cells, state.stash));
+ param.res_type, Fun(param.function), indexes.first(), indexes.second(), lhs_cells, rhs_cells, state.stash));
}
auto up = generic_mixed_merge<LCT, RCT, OCT, Fun>(lhs, rhs, param);
auto &result = state.stash.create<std::unique_ptr<Value>>(std::move(up));
