Boost logo

Boost Users :

Subject: Re: [Boost-users] C++ guru required!
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2012-02-19 13:58:36

> Assuming
> I'm correct and that Andrei's use cases don't make the case for
> static if - Is there a real case for static if.

Yes. Here's an example:

template <typename Iterator>
void advance(Iterator it, size_t n)
    static_if(iterator_category<it>::type == random_access_category_tag)
        it += n;
        for (size_t i = 0; i < n; ++i)

Were one to use a runtime if instead, and instantiate the function with
an iterator that is not random access, one would get a compiler error
of the form 'no match for operator+=(Iterator, size_t)'.

The idea is that with a runtime if, the compiler type-checks the unused
branch even if it ends up eliminating it in later on in the optimization


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at