Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void main(){
- import std.stdio;
- auto nodeI = new Node!(int)([1,2,3]);
- auto nodeF = new Node!(float)([1f,2f,3f]); /+ fails with error:
- $ dmd test.d
- test.d(26): Error: function literal __lambda4 (int t) is not callable using argument types (float)
- /Library/D/dmd/src/phobos/std/algorithm/iteration.d(480): instantiated from here: MapResult!(__lambda1, float[])
- test.d(26): instantiated from here: map!(float[])
- test.d(4): instantiated from here: Node!(float, __lambda4)
- +/
- auto nodeF2 = new Node!(float, (float f) => f*f)([1f,2f,3f]); // works
- writeln(nodeI.test);
- writeln(nodeF.test);
- }
- template Node(T, alias func=(T t) => t*t){
- // Predefining the alias function seems to cause hassle with nodeF above
- class Node{
- T[] items;
- Node[] children;
- this(T[] ts){
- items = ts[];
- }
- static if(func is null){
- auto test(){
- return items;
- }
- }
- static if(func !is null){
- auto test(){
- import std.algorithm;
- return items.map!(a => func(a));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement