Create custom data types
Dennis Ritchie via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Apr 29 16:30:52 PDT 2015
On Wednesday, 29 April 2015 at 23:22:43 UTC, Ali Çehreli wrote:
> On 04/29/2015 04:16 PM, Ali Çehreli wrote:
>
>> ref CustomInteger opOpAssign(string op, T2)(T2 rhs)
>> {
>> static if (is (T2 == CustomInteger)) {
>> mixin("value_ " ~ op ~ "= rhs.value_;");
>> return this;
>>
>> } else {
>> return this.opOpAssign!(op,
>> CustomInteger)(CustomInteger(rhs));
>
> Playing a little more, the following shorter equivalent of the
> last line works as well:
>
> return opOpAssign!op(CustomInteger(rhs));
>
> Ali
How do I disable it?
I need to prohibit all operations to the type int.
-----
auto b = Balance(42);
int t = 4;
t += b; // error in compile time
More information about the Digitalmars-d-learn
mailing list