mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #6867 from ethereum/docs-style-fix-usingfor
[DOCS] Bring Using For code examples inline with style guide
This commit is contained in:
commit
cce79ea67b
@ -33,39 +33,41 @@ Let us rewrite the set example from the
|
|||||||
|
|
||||||
pragma solidity >=0.4.16 <0.7.0;
|
pragma solidity >=0.4.16 <0.7.0;
|
||||||
|
|
||||||
|
|
||||||
// This is the same code as before, just without comments
|
// This is the same code as before, just without comments
|
||||||
library Set {
|
library Set {
|
||||||
struct Data { mapping(uint => bool) flags; }
|
struct Data { mapping(uint => bool) flags; }
|
||||||
|
|
||||||
function insert(Data storage self, uint value)
|
function insert(Data storage self, uint value)
|
||||||
public
|
public
|
||||||
returns (bool)
|
returns (bool)
|
||||||
{
|
{
|
||||||
if (self.flags[value])
|
if (self.flags[value])
|
||||||
return false; // already there
|
return false; // already there
|
||||||
self.flags[value] = true;
|
self.flags[value] = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove(Data storage self, uint value)
|
function remove(Data storage self, uint value)
|
||||||
public
|
public
|
||||||
returns (bool)
|
returns (bool)
|
||||||
{
|
{
|
||||||
if (!self.flags[value])
|
if (!self.flags[value])
|
||||||
return false; // not there
|
return false; // not there
|
||||||
self.flags[value] = false;
|
self.flags[value] = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function contains(Data storage self, uint value)
|
function contains(Data storage self, uint value)
|
||||||
public
|
public
|
||||||
view
|
view
|
||||||
returns (bool)
|
returns (bool)
|
||||||
{
|
{
|
||||||
return self.flags[value];
|
return self.flags[value];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
using Set for Set.Data; // this is the crucial change
|
using Set for Set.Data; // this is the crucial change
|
||||||
Set.Data knownValues;
|
Set.Data knownValues;
|
||||||
|
Loading…
Reference in New Issue
Block a user