Compiler error occurred when try to use a flexible template expression in preprocessor definesCompil

Discussion in 'C++' started by snnn, Mar 14, 2005.

  1. snnn

    snnn Guest

    Compiler error occurred when try to use a flexible template expression
    in preprocessor defines

    When I try to compile the following codes piece under Visual C++ .net
    2003, I get an error "Fatal Error C1017"

    typedef ::Loki::Typelist<int,::Loki::NullType> TList;
    #if ::Loki::TL::Length<TList>::value
    int x;
    #endif

    Fatal Error C1017:
    invalid integer constant expression
    The expression in an #if directive did not exist or did not evaluate to
    a constant.

    ::Loki::TL::Length<TList> is a struct some like this:
    struct Length{
    enum { value=0}; // Indeed,the value should be the length of this
    Typelist(TList)
    }

    emmm. try to the following one instead:
    enum {value=::Loki::TL::Length<TList>::value};
    #if value
    int x;
    #endif

    Ok! No error, no warning. However, as you see, that's badly! I do not
    need this extra enum value.

    So, Help me, please! Where is the syntax error in the former case?

    Thanks!
    Thanks!
    Thanks!
    snnn, Mar 14, 2005
    #1
    1. Advertising

  2. snnn

    snnn Guest

    Sorry, I typed the title twice when I copy it from word to here.

    Sorry.

    :-(
    snnn, Mar 14, 2005
    #2
    1. Advertising

  3. Re: Compiler error occurred when try to use a flexible template expressionin preprocessor definesCompiler error occurred when try to use a flexibletemplate expression in preprocessor defines

    snnn wrote:
    > Compiler error occurred when try to use a flexible template expression
    > in preprocessor defines
    >
    > When I try to compile the following codes piece under Visual C++ .net
    > 2003, I get an error "Fatal Error C1017"
    >
    > typedef ::Loki::Typelist<int,::Loki::NullType> TList;
    > #if ::Loki::TL::Length<TList>::value


    This is a preprocessor directive in which you are trying to use
    a construct only understandable by the compiler. What are you trying
    to do here?

    > int x;
    > #endif
    >
    > Fatal Error C1017:
    > invalid integer constant expression
    > The expression in an #if directive did not exist or did not evaluate to
    > a constant.
    >
    > ::Loki::TL::Length<TList> is a struct some like this:
    > struct Length{
    > enum { value=0}; // Indeed,the value should be the length of this
    > Typelist(TList)
    > }
    >
    > emmm. try to the following one instead:
    > enum {value=::Loki::TL::Length<TList>::value};
    > #if value


    Since 'value' is not a defined macro, your program will not have the
    following declaration, most likely. IOW, while it compiles, I don't think
    it produces the desired effect.

    > int x;
    > #endif
    >
    > Ok! No error, no warning. However, as you see, that's badly! I do not
    > need this extra enum value.


    Neither does it work as you want it.

    > [...]


    V
    Victor Bazarov, Mar 14, 2005
    #3
  4. snnn

    snnn Guest

    I want to expand the function declaration from a typelist such like
    this:

    #define DECLARE_FUNCTION_BY_TYPELIST_1(name,TList) \
    void name:):Loki::TL::TypeAt<TList,0>::Result p);

    so I can do that

    typedef ::Loki::Typelist<int,::Loki::NullType> TList;
    DECLARE_FUNCTION_BY_TYPELIST_1(func,TList)

    then the only thing I need to do is declare
    DECLARE_FUNCTION_BY_TYPELIST_2,DECLARE_FUNCTION_BY_TYPELIST_3,DECLARE_FUNCTION_BY_TYPELIST_4...

    I want to declare a macro which can automatic decides which macro
    should be invoke by calculating the length of that typelist.
    snnn, Mar 14, 2005
    #4
  5. Re: Compiler error occurred when try to use a flexible template expressionin preprocessor definesCompiler error occurred when try to use a flexibletemplate expression in preprocessor defines

    snnn wrote:
    > I want to expand the function declaration from a typelist such like
    > this:
    >
    > #define DECLARE_FUNCTION_BY_TYPELIST_1(name,TList) \
    > void name:):Loki::TL::TypeAt<TList,0>::Result p);
    >
    > so I can do that
    >
    > typedef ::Loki::Typelist<int,::Loki::NullType> TList;
    > DECLARE_FUNCTION_BY_TYPELIST_1(func,TList)
    >
    > then the only thing I need to do is declare
    > DECLARE_FUNCTION_BY_TYPELIST_2,DECLARE_FUNCTION_BY_TYPELIST_3,DECLARE_FUNCTION_BY_TYPELIST_4...
    >
    > I want to declare a macro which can automatic decides which macro
    > should be invoke by calculating the length of that typelist.
    >


    Cannot be done. Preprocessor has finished expanding all macros by
    the time the compiler gets to instantiated templates and generate
    the length of the typelist. Research the possibility to branch in
    the templates themselves instead of using macros.

    V
    Victor Bazarov, Mar 14, 2005
    #5
  6. snnn

    snnn Guest

    No! I tried, it doesn't work.
    value must defined as a macro but not a enum value.

    :-(

    any other solutions ?

    How to expand the function declaration from a typelist?
    snnn, Mar 14, 2005
    #6
  7. snnn

    snnn Guest

    Oh, I know, I'll try another way.

    Thank you!
    snnn, Mar 14, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ravikanth[MVP]
    Replies:
    0
    Views:
    348
    Ravikanth[MVP]
    Jul 18, 2003
  2. Marco Gerlach
    Replies:
    1
    Views:
    2,550
  3. Kevin B. Campisi
    Replies:
    1
    Views:
    447
    Yan-Hong Huang[MSFT]
    Aug 1, 2003
  4. Stan
    Replies:
    1
    Views:
    1,759
    Tian Min Huang
    Aug 30, 2003
  5. Beano
    Replies:
    0
    Views:
    413
    Beano
    Feb 16, 2005
Loading...

Share This Page