• C++ code c++14
    auto list = [](auto ...xs) { 
        return [=](auto access) { return access(xs...); }; 
    }; 
    
    auto head = [](auto xs) { 
        return xs([](auto first, auto ...rest) { return first; }); 
    }; 
    
    auto tail = [](auto xs) { 
        return xs([](auto first, auto ...rest) { return list(rest...); }); 
    }; 
    
    auto length = [](auto xs) { 
        return xs([](auto ...z) { return sizeof...(z); }); 
    }; 
    
    int len = length(list(1, '2', "3"));  // 3

Replies (0)