Add gtl::flat_hash_map example to the documentation; #416 (#418)

This commit is contained in:
Dr. Patrick Urbanke (劉自成)
2025-04-28 00:14:21 +08:00
committed by GitHub
parent 25cd3f8525
commit 5c20194598
+30
View File
@@ -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 K, class V, class Hash, class KeyEqual, class Allocator>
class is_map_like<gtl::flat_hash_map<K, V, Hash, KeyEqual, Allocator>> : public std::true_type {};
template <class R, class W, class T, class Hash, class KeyEqual, class ProcessorsType>
requires AreReaderAndWriter<R, W, gtl::flat_hash_map<std::string, T, Hash>>
struct Parser<R, W, gtl::flat_hash_map<std::string, T, Hash, KeyEqual>, ProcessorsType>
: public MapParser<R, W, gtl::flat_hash_map<std::string, T, Hash, KeyEqual>, ProcessorsType> {};
template <class R, class W, typename K, typename V, class Hash, class KeyEqual, class Allocator, class ProcessorsType>
requires AreReaderAndWriter<R, W, gtl::flat_hash_map<K, V, Hash, KeyEqual, Allocator>>
struct Parser<R, W, gtl::flat_hash_map<K, V, Hash, KeyEqual, Allocator>, ProcessorsType>
: public VectorParser<R, W, gtl::flat_hash_map<K, V, Hash, KeyEqual, Allocator>, ProcessorsType> {};
}
}
```