cxxomfort  rel.20210622
Simple backports for C++ - http://ryan.gulix.cl/fossil.cgi/cxxomfort/
List of all members
OpaqueNative< Ty, Tag > Struct Template Reference

Wraps and tags a native C type as an opaque type. More...

Detailed Description

template<typename Ty, typename Tag>
struct cxxomfort::OpaqueNative< Ty, Tag >

Wraps and tags a native C type as an opaque type.

See also
https://nullptr.nl/2018/02/phantom-types/

OpaqueNative takes a native C type, like int or float and wraps it with a Tag type as an opaque (named) type. The result is a type that can be used by explicitly accessing the underlying type where desired.

The wrapper provides access to the underlying object via the value member, but the opaque interface is used via the value() and opaque() functions.

typedef OpaqueNative<double, height_tag> Height;
typedef OpaqueNativ<unsigned, age_tag> Age;
Handle_type match_person (string name, Height h, Age a) { ... }
match_person("John Doe", 32, 33); // fails
match_person("John Doe", opaque<Height>(32), opaque<Age>(33) ); // works
match_person("John Doe", opaque<Age>(33), opaque<Age>(33) ); // fails

The documentation for this struct was generated from the following file: