Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-08 Thread Picaud Vincent via Digitalmars-d-learn
Hi Basile, Thank you for your code, it allowed me to grasp a little bit more about how to do things in D. Vincent

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Basile B. via Digitalmars-d-learn
On Monday, 7 November 2016 at 23:03:32 UTC, Picaud Vincent wrote: I need: 1/ a way to detect compile-time constant vs "dynamic" values /** * Indicates if something is a value known at compile time. * * Params: * V = The value to test. * T = Optional, the expected value type.

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Picaud Vincent via Digitalmars-d-learn
On Monday, 7 November 2016 at 23:07:27 UTC, Picaud Vincent wrote: typo... auto capacity = max(0,(size_-1)*stride_+1); To be more correct I have something like: alias IntergralConstant!(int,0) Zero_c; alias IntergralConstant!(int,1) One_c; auto capacity =

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Picaud Vincent via Digitalmars-d-learn
On Monday, 7 November 2016 at 22:18:56 UTC, Jerry wrote: On Monday, 7 November 2016 at 21:37:50 UTC, Picaud Vincent wrote: static if ( isIntegralConstant!(typeof(required_capacity()) ) { } else { } } Premature post send by error sorry Well something like: static if (

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Jerry via Digitalmars-d-learn
On Monday, 7 November 2016 at 21:37:50 UTC, Picaud Vincent wrote: static if ( isIntegralConstant!(typeof(required_capacity()) ) { } else { } } Premature post send by error sorry Well something like: static if ( isIntegralConstant!(typeof(required_capacity()) )

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Picaud Vincent via Digitalmars-d-learn
On Monday, 7 November 2016 at 21:23:37 UTC, Picaud Vincent wrote: On Monday, 7 November 2016 at 18:59:24 UTC, Jerry wrote: On Monday, 7 November 2016 at 18:42:37 UTC, Picaud Vincent wrote: template isIntegralConstant(ANY) { enum bool

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Picaud Vincent via Digitalmars-d-learn
On Monday, 7 November 2016 at 18:59:24 UTC, Jerry wrote: On Monday, 7 November 2016 at 18:42:37 UTC, Picaud Vincent wrote: template isIntegralConstant(ANY) { enum bool isIntegralConstant=__traits(identifier,ANY)=="IntegralConstant"; } A bit more elegant way of doing that would be: enum

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Jerry via Digitalmars-d-learn
On Monday, 7 November 2016 at 18:42:37 UTC, Picaud Vincent wrote: template isIntegralConstant(ANY) { enum bool isIntegralConstant=__traits(identifier,ANY)=="IntegralConstant"; } A bit more elegant way of doing that would be: enum isIntegralConstant(T) = is(T : IntegralConstant!U, U...);