Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Tuple<MakeTypelist<...>::Result...

Help
void
2010-06-08
2013-04-08
  • void
    void
    2010-06-08

    Hello,

    I have a problem with one of my Tuples I create using the Loki's library.
    I'm not entirely sure if its my compiler issue:


    typedef Tuple< MakeTypelist<uint16_t, uint16_t, uint16_t, uint8_t, uint8_t,
        uint8_t, uint8_t, uint8_t, uint8_t, uint32_t>::Result >  my_data1;

    // This one fails !!
    BOOST_STATIC_ASSERT( sizeof(my_data1) == 16);   

    //Now the last member is first
    typedef Tuple< MakeTypelist<uint32_t, uint16_t, uint16_t, uint16_t, uint8_t, uint8_t,
        uint8_t, uint8_t, uint8_t, uint8_t>::Result >  my_data2;

    //This assert is not rised
    BOOST_STATIC_ASSERT( sizeof(my_data2) == 16);


    If I just make struct with layout I want:

    typedef struct
    {
      uint16_t a;
      uint16_t b;
      uint16_t c;
      uint8_t  e;
      uint8_t  f;
      uint8_t  g;
      uint8_t  h;
      uint8_t  k;
      uint8_t  l;
      uint32_t m;
    }my_data1;

    //This assert is not raised !
    BOOST_STATIC_ASSERT( sizeof(my_dat1) == 16);

    I expected this same size when using my Tuple above …

     
  • void
    void
    2010-06-09

    correction to last assert line
    BOOST_STATIC_ASSERT( sizeof(my_data1) == 16);

     
  • void
    void
    2010-06-09

    I should add that the actual size for the first typedef tuple my_data1 that compiler generates is 40 bytes - which you will get
    if compiler packs every struct generated by Typelist to 4 bytes.  Unfortunately way above what you would want .

    I've tried different combos of data now, and the order of types in Typelist affects the size of produced type.

    Thus the Typelist likely generate not space efficient code, which you may want to consider when using it.

     
  • A typelist is not the same as a struct.  A struct's members contain data for runtime, not types for compile time.  A typelist is more like a singly linked list of types for compile time and does not contain runtime data.

    A typelist has many purposes, but its purpose is not to mimic a struct.

     
  • void
    void
    2010-06-10

    Yea i kind of saw this before using it, and yet I thought I can fit it to do what I want :)

    Thank you