Template specialisation for range of types
Meta via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Mar 12 18:52:30 PDT 2017
On Sunday, 12 March 2017 at 21:12:13 UTC, data pulverizer wrote:
> On Sunday, 12 March 2017 at 20:15:43 UTC, Meta wrote:
>> auto max(T: const U, U)(T* x, T* y) <----- Changed `ConstOf!U`
>> to `const U`
>> {
>> writeln("Const template");
>> return *x > *y ? x : y;
>> }
> How detailed can I be about the template specialisation? From
> example in the book "C++ the complete guide" we can have:
>
> /* pointer const reference */
> template<typename T>
> inline T* const& max(T* const& a, T* const&b)
> {
> return a* < b* ? b : a;
> }
>
> /* const reference const pointer */
> template<typename T>
> inline T const* const& max(T* const* const& a, T* const* const&
> b)
> {
> ...;
> }
>
> What would be the equivalent in D?
Unfortunately this is impossible in D as const is transitive. The
best you can do is try to emulate it using wrapper types. I'd
start by taking a look at std.experimental.typecons.Final, which
implements C++-style head (logical) constness.
More information about the Digitalmars-d-learn
mailing list