Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
September 30, 2012 Metaprogramming: check for ref | ||||
---|---|---|---|---|
| ||||
How can I: 1) check if function returns by ref 2) check if function parameters are ref ..outside of function body. Is parsing typeof(func).stringof only valid option? |
September 30, 2012 Re: Metaprogramming: check for ref | ||||
---|---|---|---|---|
| ||||
Posted in reply to mist | On 9/30/12, mist <none@none.none> wrote: > How can I: > 1) check if function returns by ref > 2) check if function parameters are ref > ..outside of function body. Is parsing typeof(func).stringof only > valid option? > See ParameterStorageClassTuple in std.traits http://dlang.org/phobos/std_traits.html I'm not sure about the return type though. Maybe the template should be improved to add return type into account. |
September 30, 2012 Re: Metaprogramming: check for ref | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | Thanks!
Unfortunately, return type issue is more important in my case. I'll check if implementation from ParameterStorageClassTuple can be adapted for return types though.
On Sunday, 30 September 2012 at 20:37:14 UTC, Andrej Mitrovic wrote:
> On 9/30/12, mist <none@none.none> wrote:
>> How can I:
>> 1) check if function returns by ref
>> 2) check if function parameters are ref
>> ..outside of function body. Is parsing typeof(func).stringof only
>> valid option?
>>
>
> See ParameterStorageClassTuple in std.traits
> http://dlang.org/phobos/std_traits.html
>
> I'm not sure about the return type though. Maybe the template should
> be improved to add return type into account.
|
September 30, 2012 Re: Metaprogramming: check for ref | ||||
---|---|---|---|---|
| ||||
Posted in reply to mist | On Sunday, 30 September 2012 at 20:51:54 UTC, mist wrote:
> Thanks!
> Unfortunately, return type issue is more important in my case. I'll check if implementation from ParameterStorageClassTuple can be adapted for return types though.
I think this should work:
template returnsRef(alias f)
{
enum bool returnsRef = is(typeof(
{
ParameterTypeTuple!f param;
auto ptr = &f(param);
}));
}
|
September 30, 2012 Re: Metaprogramming: check for ref | ||||
---|---|---|---|---|
| ||||
Posted in reply to jerro | On 9/30/12, jerro <a@a.com> wrote:
> I think this should work:
>
> template returnsRef(alias f)
> {
> enum bool returnsRef = is(typeof(
> {
> ParameterTypeTuple!f param;
> auto ptr = &f(param);
> }));
> }
Yep. We should add this to Phobos imo.
|
September 30, 2012 Re: Metaprogramming: check for ref | ||||
---|---|---|---|---|
| ||||
Posted in reply to jerro | Thanks!
On Sunday, 30 September 2012 at 21:20:40 UTC, jerro wrote:
> On Sunday, 30 September 2012 at 20:51:54 UTC, mist wrote:
>> Thanks!
>> Unfortunately, return type issue is more important in my case. I'll check if implementation from ParameterStorageClassTuple can be adapted for return types though.
>
> I think this should work:
>
> template returnsRef(alias f)
> {
> enum bool returnsRef = is(typeof(
> {
> ParameterTypeTuple!f param;
> auto ptr = &f(param);
> }));
> }
|
October 03, 2012 Re: Metaprogramming: check for ref | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On Sunday, 30 September 2012 at 21:34:36 UTC, Andrej Mitrovic wrote:
> On 9/30/12, jerro <a@a.com> wrote:
>> I think this should work:
>>
>> template returnsRef(alias f)
>> {
>> enum bool returnsRef = is(typeof(
>> {
>> ParameterTypeTuple!f param;
>> auto ptr = &f(param);
>> }));
>> }
>
> Yep. We should add this to Phobos imo.
Was pull request fired for this? I'd like to subscribe to get noticed when this will be in the phobos. If not, would you mind if I add one?
|
Copyright © 1999-2021 by the D Language Foundation