March 12, 2017
Meta wrote:

> On Sunday, 12 March 2017 at 20:22:33 UTC, ketmar wrote:
>> Meta wrote:
>>
>>> The reason this doesn't work is when you use ConstOf!U, it's not looking for a `const U`, it's looking for the type `ConstOf!U`. I'm not sure if this is a bug or not...
>>
>> no, not a bug. this is the way type deconstruction works: it checks if your type was constructed with a given template.
>
> Yeah, it seems to be checking the pattern rather than the type. However, ConstOf!T is just an alias for const(T), but the alias does not seem to be "unwrapped", even though they are supposed to be transparent.

yeah. "eponymous template" trick.
March 12, 2017
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?
March 13, 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.

1 2
Next ›   Last »