metaprogramming

    3热度

    4回答

    我需要生成一些东西,可以用作D programming language中用户定义类型(结构或类)的唯一句柄。优选地,这将是编译时可计算的值。如果类型的内部结构(数据布局)发生变化,但是对于大多数其他编辑(包括将同一类型编译到不同的应用程序中),我希望该句柄与该类型的名称相关联,并更改该类型的名称。 这不是一个安全的事情,所以它不需要将很难绕过或任何 我现在的想法是使用一个字符串的东西喜欢的类型名

    3热度

    11回答

    我需要一个C++模板,在给定类型和该类型对象的情况下,它可以根据类型是否为整数来做出决定,同时能够访问实际对象。我试过这个 template <typename T, T &N> struct C { enum { Value = 0 }; }; template <int &N> struct C<int, N> { enum { Value = N }; };

    5热度

    2回答

    这种方法,我想通过以下方式来“糟蹋”加成法在Groovy Groovy中的基法行为: Integer.metaClass.plus {Integer n -> delegate + n + 1} assert 2+2 == 5 我得到StackOverflowException(这并不奇怪) 。 有没有什么方法在metaclass'closure内部使用“original”加法?

    10热度

    3回答

    我有一系列“策略”对象,我认为这些对象可以方便地在一组策略类中作为类方法实现。我已指定的协议对于这一点,和创建的类,以符合(只有一个如下所示) @protocol Counter +(NSInteger) countFor: (Model *)model; @end @interface CurrentListCounter : NSObject <Counter> +(NSIntege

    3热度

    1回答

    我在动态构建一堆高级函数。我一直在使用New-PSScript,但它不允许我寻找所有的灵活性。 我读手册页,了解功能的高级参数,看到一些有关动态参数的帮助文章的结尾这给下面的示例代码 function Sample { Param ([String]$Name, [String]$Path) DynamicParam { if ($path -ma

    1热度

    4回答

    我有一个包含一些私有属性的类。我想要做的就是动态添加一些setter,仅用于执行特定块。 的,我想怎样能够例子: class Content attr_reader :a, :b def initialize @a = 1 @b = "plop" end def set(&block) extend(Setter)

    2热度

    1回答

    Django使用的Python的动态语言和元编程特性的任何优秀摘要文章?或者我们可以在这里建立吗?将其设置为维基风格条目。

    1热度

    2回答

    我想这样做如下: class String def fancy_thing appendix # Just a trivial example to ensure self and params work. # Pretend this is something complex. self.reverse + appendix end end

    28热度

    5回答

    我想找出一个方法,在Python的元数(它接收的参数个数)的元数。 现在我这样做: def arity(obj, method): return getattr(obj.__class__, method).func_code.co_argcount - 1 # remove self class Foo: def bar(self, bla): pass a

    57热度

    1回答

    我有一个模块MyModule。我动态加载类到它。我如何获得在其名称空间中定义的类的列表? 例子: def load_plugins Dir.glob(File.dirname(__FILE__) + '/plugins/*.rb') do |f| MyModule.class_eval File.read(f) end # now how can I fi