A programmer should not expect alignof to return the number of bytes in a char array. If I’m understanding what you’re suggesting correctly. I’m a little confused.

 

From: Std-Proposals <std-proposals-bounces@lists.isocpp.org> On Behalf Of Abdullah Qasim via Std-Proposals
Sent: Sunday, May 1, 2022 04:23 AM
To: Jason McKesson via Std-Proposals <std-proposals@lists.isocpp.org>
Cc: Abdullah Qasim <iamminecraftredstoner@outlook.com>
Subject: [std-proposals] operator alignof

 

 

Consider:

 

class cstring {

  // assume public functions...

 

private:

  char* ptr;         // used for dynamic allocation

  uint64_t length;

}

 

Now, assume I make cstring c(“12”)

 

Length takes 8 bytes.

Allocated char array takes 3 bytes.

Therefore:

  alignof(c)

returns 8

 

Why not 3?:

 

// In cstring

operator alignof () {

  return alignof (charArr);

}

 

Which is what the user expected!