digitalmars.D - Setting defaults to variadic template args
- Manu (8/8) Oct 02 2012 Is it possible?
- Jacob Carlborg (11/19) Oct 02 2012 struct Event
- luka8088 (18/27) Oct 02 2012 module program;
- luka8088 (23/52) Oct 02 2012 Or maybe... This seems like a much better solution:
- luka8088 (17/81) Oct 02 2012 And the simplest solution wins:
- Timon Gehr (5/9) Oct 02 2012 template Event(){alias Event!(int,float) Event;}
Is it possible?
Eg:
struct Event(T... = (int, float))
{
void F(T...); // <- should default to F(int, float)
}
Does anyone have any clever tricks that will work in this scenario? Some
magic tuple syntax?
Oct 02 2012
On 2012-10-02 15:15, Manu wrote:
Is it possible?
Eg:
struct Event(T... = (int, float))
{
void F(T...); // <- should default to F(int, float)
}
Does anyone have any clever tricks that will work in this scenario? Some
magic tuple syntax?
struct Event
{
static if (T.length == 0)
void F(int, float);
else
void F(T);
}
Perhaps?
--
/Jacob Carlborg
Oct 02 2012
module program;
import std.stdio;
import std.traits;
import std.typetuple;
struct Event (T...) {
alias EraseAll!(void, TypeTuple!(T,
Select!(T.length < 1, int, void),
Select!(T.length < 2, float, void),
)) T2;
void F (T2 args) {
writeln(typeid(typeof(args)));
}
}
void main () {
Event!() e1;
e1.F(5, 6);
}
On Tuesday, 2 October 2012 at 13:15:08 UTC, Manu wrote:
Is it possible?
Eg:
struct Event(T... = (int, float))
{
void F(T...); // <- should default to F(int, float)
}
Does anyone have any clever tricks that will work in this
scenario? Some
magic tuple syntax?
Oct 02 2012
Or maybe... This seems like a much better solution:
module program;
import std.stdio;
import std.traits;
import std.typetuple;
template SelectTrue (bool condition, T) {
static if (condition)
alias T SelectTrue;
}
struct Event (T...) {
alias TypeTuple!(T,
SelectTrue!(T.length < 1, int),
SelectTrue!(T.length < 2, float),
) T2;
void F (T2 args) {
writeln(typeid(typeof(args)));
}
}
void main () {
Event!() e1;
e1.F(5, 6);
}
On Tuesday, 2 October 2012 at 13:44:10 UTC, luka8088 wrote:
module program;
import std.stdio;
import std.traits;
import std.typetuple;
struct Event (T...) {
alias EraseAll!(void, TypeTuple!(T,
Select!(T.length < 1, int, void),
Select!(T.length < 2, float, void),
)) T2;
void F (T2 args) {
writeln(typeid(typeof(args)));
}
}
void main () {
Event!() e1;
e1.F(5, 6);
}
On Tuesday, 2 October 2012 at 13:15:08 UTC, Manu wrote:
Is it possible?
Eg:
struct Event(T... = (int, float))
{
void F(T...); // <- should default to F(int, float)
}
Does anyone have any clever tricks that will work in this
scenario? Some
magic tuple syntax?
Oct 02 2012
And the simplest solution wins:
module program;
import std.stdio;
import std.traits;
import std.typetuple;
struct Event (T1 = int, T2 = float, Telse...) {
alias TypeTuple!(T1, T2, Telse) T;
void F (T args) {
writeln(typeid(typeof(args)));
}
}
void main () {
Event!() e1;
e1.F(5, 6);
}
I hope that you found the solution that you where looking for.
On Tuesday, 2 October 2012 at 13:49:56 UTC, luka8088 wrote:
Or maybe... This seems like a much better solution:
module program;
import std.stdio;
import std.traits;
import std.typetuple;
template SelectTrue (bool condition, T) {
static if (condition)
alias T SelectTrue;
}
struct Event (T...) {
alias TypeTuple!(T,
SelectTrue!(T.length < 1, int),
SelectTrue!(T.length < 2, float),
) T2;
void F (T2 args) {
writeln(typeid(typeof(args)));
}
}
void main () {
Event!() e1;
e1.F(5, 6);
}
On Tuesday, 2 October 2012 at 13:44:10 UTC, luka8088 wrote:
module program;
import std.stdio;
import std.traits;
import std.typetuple;
struct Event (T...) {
alias EraseAll!(void, TypeTuple!(T,
Select!(T.length < 1, int, void),
Select!(T.length < 2, float, void),
)) T2;
void F (T2 args) {
writeln(typeid(typeof(args)));
}
}
void main () {
Event!() e1;
e1.F(5, 6);
}
On Tuesday, 2 October 2012 at 13:15:08 UTC, Manu wrote:
Is it possible?
Eg:
struct Event(T... = (int, float))
{
void F(T...); // <- should default to F(int, float)
}
Does anyone have any clever tricks that will work in this
scenario? Some
magic tuple syntax?
Oct 02 2012
On 10/02/2012 03:15 PM, Manu wrote:
struct Event(T... = (int, float))
{
void F(T...); // <- should default to F(int, float)
}
template Event(){alias Event!(int,float) Event;}
struct Event(T...){
void F(T...);
}
Oct 02 2012









Jacob Carlborg <doob me.com> 