Use a template parameter in a preprocessor directive?

Posted by Ranju V on Stack Overflow See other posts from Stack Overflow or by Ranju V
Published on 2010-05-25T12:08:23Z Indexed on 2010/05/25 12:11 UTC
Read the original article Hit count: 280

Filed under:
|
|

Is it possible to use a non-type constant template parameter in a preprocessor directive? Here's what I have in mind:

template <int DING>
struct Foo
{
    enum { DOO = DING };
};

template <typename T>
struct Blah
{
    void DoIt()
    {
        #if (T::Doo & 0x010)

        // somecode here

        #endif
    }
};

When I try this with something like Blah<Foo<0xFFFF>>, VC++ 2010 complains something about unmatched parentheses in the line where we are trying to use "#if". I am guessing the preprocessor doesn't really know anything about templates and this sort of thing just isn't in its domain. What say? Thanks!

© Stack Overflow or respective owner

Related posts about c++

Related posts about templates