Skip to content

Commit 5c20194

Browse files
Add gtl::flat_hash_map example to the documentation; #416 (#418)
1 parent 25cd3f8 commit 5c20194

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

docs/custom_parser.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,33 @@ struct PersonImpl {
174174
}
175175
};
176176
```
177+
178+
## Implement the `Parser` template
179+
180+
You can also directly implement the Parser template for your type.
181+
This might be beneficial when you have a third-party container type
182+
that behaves like standard containers.
183+
184+
In our example, we are implementing the template for `gtl::flat_hash_map`,
185+
but the approach should also work for similar boost containers.
186+
187+
```cpp
188+
namespace rfl {
189+
namespace parsing {
190+
191+
template <class K, class V, class Hash, class KeyEqual, class Allocator>
192+
class is_map_like<gtl::flat_hash_map<K, V, Hash, KeyEqual, Allocator>> : public std::true_type {};
193+
194+
template <class R, class W, class T, class Hash, class KeyEqual, class ProcessorsType>
195+
requires AreReaderAndWriter<R, W, gtl::flat_hash_map<std::string, T, Hash>>
196+
struct Parser<R, W, gtl::flat_hash_map<std::string, T, Hash, KeyEqual>, ProcessorsType>
197+
: public MapParser<R, W, gtl::flat_hash_map<std::string, T, Hash, KeyEqual>, ProcessorsType> {};
198+
199+
template <class R, class W, typename K, typename V, class Hash, class KeyEqual, class Allocator, class ProcessorsType>
200+
requires AreReaderAndWriter<R, W, gtl::flat_hash_map<K, V, Hash, KeyEqual, Allocator>>
201+
struct Parser<R, W, gtl::flat_hash_map<K, V, Hash, KeyEqual, Allocator>, ProcessorsType>
202+
: public VectorParser<R, W, gtl::flat_hash_map<K, V, Hash, KeyEqual, Allocator>, ProcessorsType> {};
203+
204+
}
205+
}
206+
```

0 commit comments

Comments
 (0)