-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(using-for): add support for Using-For at root level
- Loading branch information
Showing
8 changed files
with
170 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
pragma solidity ^0.8.13; | ||
|
||
|
||
struct Data { mapping(uint => bool) flags; } | ||
|
||
// Now we attach functions to the type. | ||
// The attached functions can be used throughout the rest of the module. | ||
// If you import the module, you have to | ||
// repeat the using directive there, for example as | ||
// import "flags.sol" as Flags; | ||
// using {Flags.insert, Flags.remove, Flags.contains} | ||
// for Flags.Data; | ||
using {insert, remove, contains} for Data; | ||
|
||
function insert(Data storage self, uint value) | ||
returns (bool) | ||
{ | ||
if (self.flags[value]) | ||
return false; // already there | ||
self.flags[value] = true; | ||
return true; | ||
} | ||
|
||
function remove(Data storage self, uint value) | ||
returns (bool) | ||
{ | ||
if (!self.flags[value]) | ||
return false; // not there | ||
self.flags[value] = false; | ||
return true; | ||
} | ||
|
||
function contains(Data storage self, uint value) | ||
public | ||
view | ||
returns (bool) | ||
{ | ||
return self.flags[value]; | ||
} | ||
|
||
contract C { | ||
Data knownValues; | ||
|
||
function register(uint value) public { | ||
// Here, all variables of type Data have | ||
// corresponding member functions. | ||
// The following function call is identical to | ||
// `Set.insert(knownValues, value)` | ||
require(knownValues.insert(value)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
pragma solidity ^0.8.13; | ||
|
||
struct Data { mapping(uint => bool) flags; } | ||
// Now we attach functions to the type. | ||
// The attached functions can be used throughout the rest of the module. | ||
// If you import the module, you have to | ||
// repeat the using directive there, for example as | ||
// import "flags.sol" as Flags; | ||
// using {Flags.insert, Flags.remove, Flags.contains} | ||
// for Flags.Data; | ||
using {insert, remove, contains} for Data; | ||
|
||
function insert(Data storage self, uint value) | ||
returns (bool) | ||
{ | ||
if (self.flags[value]) | ||
return false; // already there | ||
self.flags[value] = true; | ||
return true; | ||
} | ||
|
||
function remove(Data storage self, uint value) | ||
returns (bool) | ||
{ | ||
if (!self.flags[value]) | ||
return false; // not there | ||
self.flags[value] = false; | ||
return true; | ||
} | ||
|
||
function contains(Data storage self, uint value) | ||
public | ||
view | ||
returns (bool) | ||
{ | ||
return self.flags[value]; | ||
} | ||
|
||
|
||
contract C { | ||
Data knownValues; | ||
|
||
function register(uint value) public { | ||
// Here, all variables of type Data have | ||
// corresponding member functions. | ||
// The following function call is identical to | ||
// `Set.insert(knownValues, value)` | ||
require(knownValues.insert(value)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters