开发者

"Un-const"-ing a type in D

开发者 https://www.devze.com 2023-02-04 08:51 出处:网络
I\'m trying to write a template named Unconst that would turn something like const(int) into int; in other words

I'm trying to write a template named Unconst that would turn something like const(int) into int; in other words

Unconst!(const(int))

should give

int

I can't figure out how, though... any creative ideas for making this work?

(Extension: It would be great if the method could be extended to also work with shared and other type construct开发者_运维知识库ors.)


Never mind, I found the answer myself...

template Unconst(T)
{
    static if (is(T U == const U))
        alias U Unconst;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号