metalang99: Don't understand how to recurse
I have read the tutorial and write the code according to example but it doesn’t work. I took several hours to try different patterns with v() or without v() but still don’t figure out how to use it. So I came here to find some help, here is the code.
#define _GetUnderlyingType(LayerNumber,CurrentType) \
std::enable_if_t<_IsEligibleType<CurrentType,LayerNumber,_default_index>::value, \
typename _IsEligibleType<CurrentType,LayerNumber,_default_index>::underlying_type>
#define _ConstructGetUnderlyingType(TotalLayer,StartLayer,T) ML99_natMatchWithArgs(TotalLayer, v(_ConstructGetUnderlyingType_),StartLayer,T)
#define _ConstructGetUnderlyingType_Z_IMPL(StartLayer,T) v(T)
#define _ConstructGetUnderlyingType_S_IMPL(TotalLayer,StartLayer,T) \
_GetUnderlyingType(StartLayer-TotalLayer+2,_ConstructGetUnderlyingType(v(TotalLayer),StartLayer,T))
ML99_EVAL(_ConstructGetUnderlyingType(v(1), v(1), v(T)));
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 18 (9 by maintainers)
With your patience and help I finally finished my own project, thank you very much.
By the way, there’s a more neat way to do the same:
Output:
We could do the trick with some variadics metaprogramming:
This is a fully C99-compliant (C++11) way to accomplish your job.
Oh, It’s my fault, forget it.😂 Thank you for you patience.
On my computer, it just fails:
This is because
_GetUnderlyingTypereduces to commas, which are treated as macro arguments. To fix it, you can wrap the call usingML99_tupleand thenML99_UNTUPLEthem:The expansion output:
Hope this helps.
Try this:
The above code gives the following output:
The thing is that an invocation of
_ConstructGetUnderlyingTypeis a Metalang99 term, but in your example, you feed it to_GetUnderlyingType, which is not evaluated by Metalang99 further. In my example, I define_GetUnderlyingTypeas a ML99-compliant metafunction so its arguments are fully evaluated.