Hello,
While solidity native constructions like mapping and arrays are good enough for most use-cases, the inability to search an array in constant time, and the inability to traverse are mapping, are sometimes critical to smart contract developers. Combining the two into a richer structure trades compuation for storage. This trade might not be effective to everyone, but it is sometime necessary.
This thing is, many people are writting such structures, are re-use is limited by the specialisation of the type (are you considering structure containing bytes32? addresses? bytes4?). We could ask the devs to cast all inbound/outbound values, but that raises other issues.
In order to stop having duplicates of my structure in each an everyone of my projects, I made a dedicated package with code for sets (searchable list without duplicate) and map (traverseable key-value store). The “templating” is achieved using sed
for text replacement … which is working but limited to natural types as it is not (yet?) smart enough to add memory
/calldata
where needed.
I’ll continue developping this repo, and everyone is free to contribute, but I think at some point this should be part of either the solidity langage or some recognised package like openzeppelin.
Is there any similar effort I might have missed? Have templated structs/contracts/libraries ever been considered in solidity?