On Thursday, 24 November 2016 at 17:59:55 UTC, ag0aep6g wrote:
Took me a bit to find it, but it is documented:
"If both a template with a sequence parameter and a template
without a sequence parameter exactly match a template
instantiation, the template without a TemplateSequenceParameter
is
On Thursday, 24 November 2016 at 17:47:04 UTC, Steven
Schveighoffer wrote:
void foo(T)(T t){writeln("a");}
void foo(T...)(T t){writeln("b");}
foo(1);
Compiles? If so, which prints out?
I was surprised by the answer. I can't find docs for it. Is the
behavior intended?
-Steve
That is expect
On 11/24/2016 06:47 PM, Steven Schveighoffer wrote:
void foo(T)(T t){writeln("a");}
void foo(T...)(T t){writeln("b");}
foo(1);
Compiles? If so, which prints out?
I was surprised by the answer. I can't find docs for it. Is the behavior
intended?
Took me a bit to find it, but it is documented:
On 01/22/2016 07:41 AM, Darrell Gallion wrote:
Defining the template [specializations] within another function, fails.
Reported:
https://issues.dlang.org/show_bug.cgi?id=15592
Ali
On Friday, 22 January 2016 at 13:03:52 UTC, Darrell Gallion wrote:
On Friday, 22 January 2016 at 11:23:56 UTC, Marc Schütz wrote:
On Friday, 22 January 2016 at 01:33:42 UTC, Darrell Gallion
wrote:
void foo(A)()
if (!is (A == int)) {
pragma(msg, "int");
}
void foo(A)()
if (i
On Friday, 22 January 2016 at 13:03:52 UTC, Darrell Gallion wrote:
On Friday, 22 January 2016 at 11:23:56 UTC, Marc Schütz wrote:
On Friday, 22 January 2016 at 01:33:42 UTC, Darrell Gallion
wrote:
void foo(A)()
if (!is (A == int)) {
pragma(msg, "int");
}
void foo(A)()
if (i
On Friday, 22 January 2016 at 11:23:56 UTC, Marc Schütz wrote:
On Friday, 22 January 2016 at 01:33:42 UTC, Darrell Gallion
wrote:
void foo(A)()
if (!is (A == int)) {
pragma(msg, "int");
}
void foo(A)()
if (is (A == int[])) {
pragma(msg, "int[]");
}
void main() {
foo!
On Friday, 22 January 2016 at 01:33:42 UTC, Darrell Gallion wrote:
void foo(A)()
if (!is (A == int)) {
pragma(msg, "int");
}
void foo(A)()
if (is (A == int[])) {
pragma(msg, "int[]");
}
void main() {
foo!(int)();
foo!(int[])();
}
===
source\app.d(15): Erro
On Friday, 22 January 2016 at 00:08:56 UTC, Ali Çehreli wrote:
On 01/21/2016 03:37 PM, Darrell Gallion wrote:
How do you create a template that accepts many types.
But overrides just one of them?
Don't want to write out all of the specializations.
Hours of google and I'm sure it's simple...
-=
On 01/21/2016 03:37 PM, Darrell Gallion wrote:
How do you create a template that accepts many types.
But overrides just one of them?
Don't want to write out all of the specializations.
Hours of google and I'm sure it's simple...
-=Darrell
The straightforward approach is tricky because the ':
On Thu, Jan 21, 2016 at 11:37:34PM +, Darrell Gallion via
Digitalmars-d-learn wrote:
> How do you create a template that accepts many types.
> But overrides just one of them?
> Don't want to write out all of the specializations.
>
> Hours of google and I'm sure it's simple...
[...]
I'm afrai
On Monday, December 21, 2015 19:54:53 Shriramana Sharma via Digitalmars-d-learn
wrote:
> Thanks all for your replies. One question:
>
> Jonathan M Davis wrote:
> > Alternatively, you can use static if, though you're only dealing
> > with one template in that case. e.g.
>
> But if we wanted to depr
Thanks all for your replies. One question:
Jonathan M Davis wrote:
> Alternatively, you can use static if, though you're only dealing
> with one template in that case. e.g.
But if we wanted to deprecate one of the alternatives, then we necessary
need to declare two templates with the same name a
On Monday, 21 December 2015 at 11:12:10 UTC, Jonathan M Davis
wrote:
On Monday, 21 December 2015 at 11:07:16 UTC, Jonathan M Davis
wrote:
For your example to work with template constraints, the most
straightforward solution would be
void func(T)(T t)
if(!isIntegral!T)
{
writeln(1);
}
On Monday, 21 December 2015 at 11:07:16 UTC, Jonathan M Davis
wrote:
For your example to work with template constraints, the most
straightforward solution would be
void func(T)(T t)
if(!isIntegral!T)
{
writeln(1);
}
void func(T)(T t)
if(isIntegral!T)
{
writeln(2);
}
Alternati
On Monday, December 21, 2015 15:14:20 Shriramana Sharma via Digitalmars-d-learn
wrote:
> Hello. I want to define a template specialization using traits:
>
> import std.stdio, std.traits;
> void func(T)(T t) { writeln(1); }
> void func(T)(T t) if(isIntegral!T) { writeln(2); }
> void main()
> {
>
On Monday, 21 December 2015 at 09:44:20 UTC, Shriramana Sharma
wrote:
Hello. I want to define a template specialization using traits:
import std.stdio, std.traits;
void func(T)(T t) { writeln(1); }
void func(T)(T t) if(isIntegral!T) { writeln(2); }
void main()
{
func(1);
}
But I'm getting a
On 5/16/13, Jack Applegame wrote:
> Why this doesn't compile?
I think this is a bug.
Thanks everyone.
Please write one, overloading of functions with templates is an
important and basic thing.
http://d.puremagic.com/issues/show_bug.cgi?id=3941
Steven Schveighoffer:
> I know this is planned, because it's in TDPL. BTW, are there any bug
> reports for this?
Please write one, overloading of functions with templates is an important and
basic thing.
Bye,
bearophile
On Tue, 08 Jun 2010 17:25:43 -0400, Larry Luther
wrote:
This code:
import std.stdio;
class A {
void get (T:ubyte)(T[] buffer) {
writefln( "get (T:ubyte)(T[] buffer)\n");
}
void get (T:byte)(T[] buffer) {
writefln( "get (T:byte)(T[] buffer)\n");
}
void get (T)(T[] buffe
On Tue, 08 Jun 2010 17:25:43 -0400, Larry Luther
wrote:
This code:
import std.stdio;
class A {
void get (T:ubyte)(T[] buffer) {
writefln( "get (T:ubyte)(T[] buffer)\n");
}
void get (T:byte)(T[] buffer) {
writefln( "get (T:byte)(T[] buffer)\n");
}
void get (T)(T[] buffe
Larry Luther wrote:
Thanks guys.
Simen asked: "Is there a problem?".
Well, I kind of expected a "ubyte" buffer to be matched with a
"get(T:ubyte)".
I thought methods were searched for the "best" match.
No, C++ does it that way, and it gets horrendously complicated.
In D, it has to ma
Thanks guys.
Simen asked: "Is there a problem?".
Well, I kind of expected a "ubyte" buffer to be matched with a
"get(T:ubyte)".
I thought methods were searched for the "best" match.
Larry
On 06/08/2010 05:01 PM, Robert Clipsham wrote:
On 08/06/10 22:25, Larry Luther wrote:
Q: Is this the way it's supposed to be?
Yes, byte implicitly casts to ubyte so it's accepted. Try switching the
templates round, they will both be byte. The way around this is to add
template constraints to t
On 08/06/10 22:25, Larry Luther wrote:
Q: Is this the way it's supposed to be?
Yes, byte implicitly casts to ubyte so it's accepted. Try switching the
templates round, they will both be byte. The way around this is to add
template constraints to the templates:
void get(T:ubyte)(T[] buffer)
Larry Luther wrote:
get (T:ubyte)(T[] buffer)
get (T:ubyte)(T[] buffer)
get (T)(T[] buffer)
Q: Is this the way it's supposed to be?
Looks very much correct, yes. Is there a problem?
--
Simen
On 02/01/2010 07:29 PM, Ali Çehreli wrote:
daoryn wrote:
> According to http://digitalmars.com/d/2.0/template.html it is
possible to specify template specialization so that DMD prefers them
when instanciating templates, however the following code:
>
>
> -
> im
daoryn wrote:
> According to http://digitalmars.com/d/2.0/template.html it is
possible to specify template specialization so that DMD prefers them
when instanciating templates, however the following code:
>
>
> -
> import std.stdio;
>
> void print(T)(T thing)
> {
On 02/01/2010 04:19 PM, daoryn wrote:
The whole point of specialisation (and of templates in general) is to have
functions that work for any type. Having to forcibly specify a type is like
casting to a specific overload of a function. Why add clutter to the syntax
when the language advertises
Tomek SowiÅski Wrote:
> Dnia 31-01-2010 o 21:39:21 Ali Ãehreli napisaÅ(a):
>
> > � wrote:
> >> Dnia 31-01-2010 o 20:59:47 Tomek Sowi�ski napisa�(a):
> >>
> >>> // specialization needed to limit matching types
> >>> void print(T:int)(T thing)
> >> To be clear -- I did this to silence t
> It works with dmd 2.040 without the :int specialization.
No it doesnt. Did you use specific compiler flags? Also check that you are
using the source I posted and not the modified versions presented which served
only to circumvent compiler warnings and not answer the original question: is
it a
Ellery Newcomer Wrote:
> I haven't gotten around to templates yet, so I don't grok them quite as
> well as I'd like, but it looks like DMD is having trouble deducing T
> from the parameter given.
>
> print([1,2,3]) fails to match the specialized template, even when the
> general template is re
Daniel Murphy Wrote:
> daoryn Wrote:
>
> > According to http://digitalmars.com/d/2.0/template.html it is possible to
> > specify template specialization so that DMD prefers them when instanciating
> > templates, however the following code:
> >
> >
> > -
> > imp
Dnia 31-01-2010 o 21:39:21 Ali Çehreli napisał(a):
� wrote:
Dnia 31-01-2010 o 20:59:47 Tomek Sowi�ski napisa�(a):
// specialization needed to limit matching types
void print(T:int)(T thing)
To be clear -- I did this to silence the compiler saying the call with
array matches more than one
� wrote:
Dnia 31-01-2010 o 20:59:47 Tomek Sowi�ski napisa�(a):
// specialization needed to limit matching types
void print(T:int)(T thing)
To be clear -- I did this to silence the compiler saying the call with
array matches more than one function template declaration. I'm not sure
whether
Dnia 31-01-2010 o 20:59:47 Tomek Sowiński napisał(a):
// specialization needed to limit matching types
void print(T:int)(T thing)
To be clear -- I did this to silence the compiler saying the call with
array matches more than one function template declaration. I'm not sure
whether the comp
Dnia 31-01-2010 o 19:49:44 daoryn napisał(a):
import std.stdio;
void print(T)(T thing)
{
writeln("Calling print(T)");
writeln(T.stringof);
}
void print(T:T[])(T[] things)
{
writeln("Calling print(T[])");
writeln(T.stringof);
}
void main()
{
print(3);
I haven't gotten around to templates yet, so I don't grok them quite as
well as I'd like, but it looks like DMD is having trouble deducing T
from the parameter given.
print([1,2,3]) fails to match the specialized template, even when the
general template is removed.
If you force the template
daoryn Wrote:
> According to http://digitalmars.com/d/2.0/template.html it is possible to
> specify template specialization so that DMD prefers them when instanciating
> templates, however the following code:
>
>
> -
> import std.stdio;
>
> void print(T)(T thin
41 matches
Mail list logo