www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Checking for Homogeneous Tuples

reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
How do I check that all the elements of a std.typecons.Tuple all 
fulfil a specific predicate, in my case all have a specific type:

Something like

     import std.typecons : isTuple;
     enum isTupleOf(T, E) = isTuple!T && is(MAGIC(T, E));
Sep 15 2015
next sibling parent John Colvin <john.loughran.colvin gmail.com> writes:
On Tuesday, 15 September 2015 at 16:54:22 UTC, Nordlöw wrote:
 How do I check that all the elements of a std.typecons.Tuple 
 all fulfil a specific predicate, in my case all have a specific 
 type:

 Something like

     import std.typecons : isTuple;
     enum isTupleOf(T, E) = isTuple!T && is(MAGIC(T, E));
std.meta.allSatisfy!(SomePredicateTemplate, T.Types);
Sep 15 2015
prev sibling next sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
If it is a tuple of values too, you could just try to form an 
array out of it: `static if (__traits(compiles, [your_tuple]))`. 
But allSatisfy might be better.

For the predicate there, remember it needs to take a template 
argument.
Sep 15 2015
prev sibling parent reply Meta <jared771 gmail.com> writes:
On Tuesday, 15 September 2015 at 16:54:22 UTC, Nordlöw wrote:
 How do I check that all the elements of a std.typecons.Tuple 
 all fulfil a specific predicate, in my case all have a specific 
 type:

 Something like

     import std.typecons : isTuple;
     enum isTupleOf(T, E) = isTuple!T && is(MAGIC(T, E));
I made a pull request for this a long time ago but it was rejected. https://github.com/D-Programming-Language/phobos/pull/1672
Sep 15 2015
parent =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Tuesday, 15 September 2015 at 17:41:07 UTC, Meta wrote:
 I made a pull request for this a long time ago but it was 
 rejected.

 https://github.com/D-Programming-Language/phobos/pull/1672
I'll try again because it's needed here https://github.com/D-Programming-Language/phobos/pull/3395 ;)
Sep 15 2015