Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. const std = @import("std");
  2. const builtin = @import("builtin");
  3.  
  4. //Id like to print the arg types of this function
  5. fn foo(n: usize, comptime T: type) usize {
  6.     return n;
  7. }
  8.  
  9. fn makefunc(comptime func: var) type {
  10.     const TargetFnType = @typeOf(func);
  11.     const target_fn_info = @typeInfo(TargetFnType).Fn;
  12.     const args = target_fn_info.args;
  13.  
  14.     return struct {
  15.         fn call(n: args[0].arg_type.?, comptime t: args[1].arg_type.?) void {
  16.             std.debug.warn("{} {}", n, @typeName(t));
  17.         }
  18.     };
  19. }
  20. pub fn main() void {
  21.     comptime var f = makefunc(foo);
  22.  
  23.     f.call(10, @typeOf(foo));
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement