OpenEnroth 73e68f7
Loading...
Searching...
No Matches
RegularBinarySource Concept Reference

#include <BinaryConcepts.h>

Concept definition

template<class T>
Definition: BinaryConcepts.h:67
Definition: BinaryConcepts.h:7

Detailed Description

Binary serialization provides a set of overloads, and when there's too many, a moment comes when they need to be explicitly ordered. Consider the following overloads:

template<class T, class... Tag>
void serialize(const T &src, Blob *dst, const Tag &...); // #1
template<class Src, class Dst, class Via>
void serialize(const Src &src, Dst *dst, ViaTag<Via>); // #2
void serialize(const IndoorDelta_MM7 &src, OutputStream *dst)
Definition: CompositeSnapshots.cpp:278
Definition: Blob.h:23
Definition: SnapshotSerialization.h:9

And the following call:

Blob blob;
serialize(SomeData{}, &blob, tags::via<SomeData_Bin>);

This call is ambiguous because the types provided match both overloads, with neither one being a better match. Besides, the ambiguity is genuine here - the order really doesn't matter, so whether #1 calls into #2 or the other way around, result stays the same. However, this is C++, so we need to:

  1. Pick the order we like.
  2. Guide the compiler into it.

In this particular case it makes sense to disambiguate on src and dst first, and then process all the tags. How to do it? We can introduce the notion of 'proxy' binary serialization types:

Thus, proxy types stand in contrast to regular, or "leaf" types - types for which non-template overloads are provided. All overloads that process tags require regular src and dst arguments, and this provides natural ordering:

  1. First, all src / dst transformations are carried out.
  2. Then, tags are applied in order.

To achieve this, the following concepts are provided:

Then, for the types that actually are proxies, the following type traits are provided for specialization:

See also
RegularBinarySink
RegularBinarizable