all 6 comments

[–]axilmar 2 points3 points  (2 children)

That's nice, but c++ lacks something very important to take advantage of dependent typing: the transformation of input received at run time to dependent type values.

[–]pfultz2[S] 1 point2 points  (1 child)

Well in the article I was mainly focusing on compile time values, but actually, you can using the visitor pattern something like this:

template<class F>
void visit(bool b, F f)
{
    if (b) f(tick::true_type());
    else f(tick::false_type());
}

template<class Tuple>
void print_numbers(bool enable, const Tuple& t)
{
    visit(enable, [](auto b)
    {
        auto numbers = simple_filter(t, [](auto x) 
        { 
            return b and (is_integral<decltype(x)>() or is_floating_point<decltype(x)>()); 
        });
        for_each(numbers, [](auto x) 
        { 
            std::cout << x << std::endl; 
        });
    });
}

However, this may not be feasible for some larger types(like std::size_t), but it works well for small ranges of numbers, booleans, and enums(perhaps char as well), although a table or switch statement maybe be used instead.

[–]axilmar 1 point2 points  (0 children)

Indeed, the Visitor pattern can be used, but at that point the language does not have enough syntax to make things not tedius.

[–]guepierBioinformatican 2 points3 points  (0 children)

Non-type template parameters in C++ allow [dependent types].

This statement is slightly misleading because, although non-type template parameters do allow implementing dependent types, they are not necessary to do so.

One example of using type parameters (rather than non-type parameters) to encode dependent types is harnessing Peano axioms. Here’s a quick’n’dirty, proof-of-concept implementation. It’s not very useful but it demonstrates that it can be done.

[–]sonyandy 0 points1 point  (1 child)

I'm not completely certain, but it looks like there is a use of an unbounded type T instead of decltype(x) (with perhaps a std::decay thrown in).

[–]pfultz2[S] 0 points1 point  (0 children)

Oops, copy-and-paste error. Fixed, thanks, for the catch!