From 5c201945986cc91e65fa9f6ae2d146341ef1e7ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dr=2E=20Patrick=20Urbanke=20=28=E5=8A=89=E8=87=AA=E6=88=90?= =?UTF-8?q?=29?= Date: Mon, 28 Apr 2025 00:14:21 +0800 Subject: [PATCH] Add gtl::flat_hash_map example to the documentation; #416 (#418) --- docs/custom_parser.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/custom_parser.md b/docs/custom_parser.md index b7ae2446..8a40e232 100644 --- a/docs/custom_parser.md +++ b/docs/custom_parser.md @@ -174,3 +174,33 @@ struct PersonImpl { } }; ``` + +## Implement the `Parser` template + +You can also directly implement the Parser template for your type. +This might be beneficial when you have a third-party container type +that behaves like standard containers. + +In our example, we are implementing the template for `gtl::flat_hash_map`, +but the approach should also work for similar boost containers. + +```cpp +namespace rfl { +namespace parsing { + +template +class is_map_like> : public std::true_type {}; + +template + requires AreReaderAndWriter> +struct Parser, ProcessorsType> + : public MapParser, ProcessorsType> {}; + +template + requires AreReaderAndWriter> +struct Parser, ProcessorsType> + : public VectorParser, ProcessorsType> {}; + +} +} +```