Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-03-22 00:47:26


David Abrahams wrote:
> I'm looking for a legal way to cause certain constructs to fail to
> compile based on what templates have been instantiated at
> that point in the program. The catch is that I also want it to be
> legal to compile the same constructs in other translation units
> (and, if I have to settle for something permissive, earlier in the
> same translation unit) where the preventing templates have not
> been instantiated. Most approaches to this problem result in
> ODR violations, AFAIK. I'm thinking that there may be
> some promise in the use of the Barton & Nackmann trick in
> combination with the unnamed namespace, but I'm not very
> clear about it.
> Has anyone already solved this puzzle?

I am not quote sure that I understood your requirements completely, but may
be something like this:

namespace {
template< typename T >
struct disable { typedef T type; };
}

template< typename T >
struct my
{
    my() { typedef typename disable<my>::type t; }
};

namespace {
template<> struct disable< my<int> >;
}

int main()
{
    my<long> m1; // ok
    my<int> m2; // error
    return 0;
}

?

Aleksey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk