On Wednesday, 18 August 2021 at 06:53:51 UTC, Tejas wrote:
void funcTemplate(T:int)(T a){
writeln("argument is int");
}
void funcTemplate(T : long)(T a){
writeln("argument is long integer");
}
void main(){
int a;
long b;
func(a);
func(b);
funcTemplate(a);
On Wednesday, 18 August 2021 at 05:33:13 UTC, james.p.leblanc
wrote:
On Tuesday, 17 August 2021 at 20:28:20 UTC, Alexandru Ermicioi
wrote:
On Tuesday, 17 August 2021 at 19:53:52 UTC, james.p.leblanc
wrote:
Wow! That is absolutely beautiful ... I had never seen (or
even
imagined) a recursive
On Wednesday, 18 August 2021 at 05:33:13 UTC, james.p.leblanc
wrote:
If I wanted to ensure that a function accepts only arguments of
byte, int, uint, long, etc. (i.e. integer-like types). Is the
accepted way to do this like so?:
**auto foo( T : long )(T a, T b){ ... }**
I very much prefer
On Tuesday, 17 August 2021 at 20:28:20 UTC, Alexandru Ermicioi
wrote:
On Tuesday, 17 August 2021 at 19:53:52 UTC, james.p.leblanc
wrote:
Wow! That is absolutely beautiful ... I had never seen (or
even
imagined) a recursive template! This expands my mind in a good
way ... and is going into m
On Tuesday, 17 August 2021 at 20:29:51 UTC, james.p.leblanc wrote:
So, below
is my code:
import std.stdio;
import std.meta : AliasSeq;
template isAmong(T, S...) {
static if (S.length == 0)
enum isAmong = false;
else
enum isAmong = is(T == S) || isAmong(T, S[1..$]);
}
alias My
On Tue, Aug 17, 2021 at 07:53:52PM +, james.p.leblanc via
Digitalmars-d-learn wrote:
> On Tuesday, 17 August 2021 at 19:44:29 UTC, H. S. Teoh wrote:
> > You could use a helper template and an AliasSeq for this:
> >
> > template isAmong(T, S...) {
> > static if (S.length == 0)
On Tuesday, 17 August 2021 at 20:13:59 UTC, Paul Backus wrote:
FYI: in this particular case, you can use
std.meta.staticIndexOf instead of writing the recursion out
yourself:
import std.meta: staticIndexOf;
enum isAmong(T, S...) = staticIndexOf!(T, S) >= 0;
Docs: https://phobos.dpldo
On Tuesday, 17 August 2021 at 19:53:52 UTC, james.p.leblanc wrote:
Wow! That is absolutely beautiful ... I had never seen (or even
imagined) a recursive template! This expands my mind in a good
way ... and is going into my toolbox immediately.
Best Regards,
James
Just don't over rely on it.
On Tuesday, 17 August 2021 at 19:53:52 UTC, james.p.leblanc wrote:
On Tuesday, 17 August 2021 at 19:44:29 UTC, H. S. Teoh wrote:
You could use a helper template and an AliasSeq for this:
template isAmong(T, S...) {
static if (S.length == 0)
enum
On Tuesday, 17 August 2021 at 19:44:29 UTC, H. S. Teoh wrote:
You could use a helper template and an AliasSeq for this:
template isAmong(T, S...) {
static if (S.length == 0)
enum isAmong = false;
else
enum
On Tue, Aug 17, 2021 at 07:22:54PM +, james.p.leblanc via
Digitalmars-d-learn wrote:
[...]
> auto moo(T : (int || float || mySpecialStruct )(T myMoo) {•••}
>
> When re-using any such sets, it would be nice to define the set as
> follows:
>
> S = (int || float || mySpecialStruct)
>
> and the
On Tuesday, 17 August 2021 at 18:28:53 UTC, Steven Schveighoffer
wrote:
On 8/17/21 2:11 PM, james.p.leblanc wrote:
Evening All,
[Template
constraints](https://dlang.org/spec/template.html#template_constraints).
-Steve
Dear All,
Thanks! I was aware of, and have used template constraints
On 8/17/21 2:11 PM, james.p.leblanc wrote:
Evening All,
Eponymous templates allow a nice calling syntax. For example, "foo"
here can
be called without needing the exclamation mark (!) at calling sites. We
see that
foo is restricting a, and b to be of the same type ... so far, so good.
auto
On 8/17/21 11:11 AM, james.p.leblanc wrote:
> auto foo(T)(T a, T b) { ... }
>
> Now, suppose I need to restrict "T" only certain subsets of variable
types.
There are template constraints:
import std.traits;
auto foo(T)(T a, T b)
if (isArray!T) {
// ...
}
auto foo(T)(T a, T b)
if (isFloati
On Tue, Aug 17, 2021 at 06:11:56PM +, james.p.leblanc via
Digitalmars-d-learn wrote:
> Evening All,
>
> Eponymous templates allow a nice calling syntax. For example, "foo"
> here can be called without needing the exclamation mark (!) at calling
> sites. We see that foo is restricting a, and
On Tuesday, 17 August 2021 at 18:11:56 UTC, james.p.leblanc wrote:
Is there a more elegant way, to do this?
Regards,
James
PS Any violations should be caught at compile time.
That is template specialization:
```
auto moo(T : YourSpecialClassOrDType)(T myMoo) {•••}
```
You can also declare o
Evening All,
Eponymous templates allow a nice calling syntax. For example,
"foo" here can
be called without needing the exclamation mark (!) at calling
sites. We see that
foo is restricting a, and b to be of the same type ... so far, so
good.
auto foo(T)(T a, T b) { ... }
Now, suppose I n
17 matches
Mail list logo