Are these identical? Or is there a different usage for the (T : something) form?
auto opCast(T)() if (is(T == bool)) {
return _obj !is null;
}
auto opCast(T : bool)() {
return _obj !is null;
}
May 15, 2021 What is the difference between these template declaration forms? | ||||
---|---|---|---|---|
| ||||
Are these identical? Or is there a different usage for the (T : something) form?
|
May 15, 2021 Re: What is the difference between these template declaration forms? | ||||
---|---|---|---|---|
| ||||
Posted in reply to cc | On Saturday, 15 May 2021 at 08:37:21 UTC, cc wrote: >Are these identical? Or is there a different usage for the (T : something) form?
They are the same in this case. >
While the docs says it matches the most specialized type, which is bool in this case, IIRC it is actually takes anything convertible to bool despite what the docs says. Anyway I would usually pick this form where possible as it yields cleaner error messages unlike arbitrary template constraint "stuff X doesnt takes Y, did you mean (basically X but not)" message that who knows what it wants you to do. |