blob: 90597059e406cd5047fd9444289f4819732e297b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#pragma once
#include "public.h"
#include <ranges>
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
// Can be specialized to make your dictionary satisfy CMergeableDictionary.
template <class TDictionary>
struct TMergeDictionariesTraits
{
static auto MakeIterableView(const TDictionary& dict)
requires false;
};
////////////////////////////////////////////////////////////////////////////////
namespace NDetail {
template <class T>
struct TMergeableDictionaryImpl
{
using TView = std::invoke_result_t<decltype(&TMergeDictionariesTraits<T>::MakeIterableView), const T&>;
using TIterator = std::ranges::iterator_t<TView>;
using TValue = typename std::iterator_traits<TIterator>::value_type;
static constexpr bool ValidSize = requires {
{ std::tuple_size<TValue>::value } -> std::same_as<const size_t&>;
} && (std::tuple_size<TValue>::value == 2);
static constexpr bool CorrectTupleElements = requires {
typename std::tuple_element<0, TValue>::type;
std::same_as<typename std::tuple_element<0, TValue>::type, TString>;
typename std::tuple_element<1, TValue>::type;
std::same_as<typename std::tuple_element<1, TValue>::type, NYson::TYsonString>;
};
};
} // namespace NDetail
////////////////////////////////////////////////////////////////////////////////
template <class T>
concept CMergeableDictionary =
requires (const T& dict) {
TMergeDictionariesTraits<T>::MakeIterableView(dict);
} &&
NDetail::TMergeableDictionaryImpl<T>::ValidSize &&
NDetail::TMergeableDictionaryImpl<T>::CorrectTupleElements;
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT
|