Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.stdio;
- import std.string : format;
- enum Op
- {
- Equals,
- NotEquals,
- }
- struct BinaryExpr(T)
- {
- T left;
- T right;
- Op op;
- }
- struct Column(T)
- {
- T value;
- alias value this;
- bool opEquals(T b)
- {
- return b == value;
- }
- BinaryExpr!T opEquals(T b)
- {
- return BinaryExpr!T(this, b, Op.Equals);
- }
- }
- void filter(T)(BinaryExpr!T e)
- {
- writeln(e);
- }
- class User
- {
- Column!int id;
- Column!string name;
- Column!string password;
- public override string toString()
- {
- return "%d, %s, %s".format(id, name, password);
- }
- }
- void main()
- {
- auto user = new User();
- with (user)
- {
- id = 10;
- name = "John Doe";
- password = "qwe123";
- }
- filter(user.id == 10);
- // Here is the error
- if (user.id == 10) {
- writeln("User ID is 10");
- }
- writeln(user);
- }
Add Comment
Please, Sign In to add comment