Results 1 to 3 of 3

Thread: Vector's misplaced const attribute

  1. #1

    Default Vector's misplaced const attribute

    Thre was a little mistake with the cast operator of vectors :
    Type *const means that the pointer is const, and so, doesn't means anything because the user get a copy of the pointer, and can do what he wants with it.
    Type const * means that the type is const, and that the user can't modify it (that's what is expected to be returned by a const function).

    So, the patch. The second patch remove the cast of this pointer. Ok, it should works because the class do not inheritate from any others, and the class Vector is probably in the set of "stanard_layout" classes. But, because casting this is never a good idea, it's safer to :
    1) Explicitly tell that the code rely on the order of fields
    2) Return a ref to the first field.

    There are of course many other solution, but I think it's the closest to the clan's philosophy. Feel free to do not apply the second patch.

    Edit : I also add the "half_float_vector" patch.
    Attached Files Attached Files

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Instead, I suggest that we remove all of:

    Code:
    	const Type &operator[](unsigned int i) const { return ((Type *) this)[i]; }
    	Type &operator[](unsigned int i) { return ((Type *) this)[i]; }
    	operator Type *() { return (Type *) this; }
    	operator Type * const() const { return (Type * const) this; }
    (for various reasons, too tired to mention now)

  3. #3

    Default

    I'm ok with removing them if it's ok for all clanLib's developers.

    One more const patch (same thing).
    Attached Files Attached Files

Similar Threads

  1. Growtopia Vector Edits
    By biglosr in forum Fan Creations
    Replies: 0
    Last Post: 05-19-2013, 07:07 PM
  2. Big slowdown while drawing tiles from a vector
    By RootKernel in forum Official ClanLib SDK Forums
    Replies: 6
    Last Post: 10-19-2012, 02:51 PM
  3. Replies: 3
    Last Post: 08-13-2010, 10:17 PM
  4. Support for Scalable Vector Graphics
    By fdaniels in forum Novashell Game Creation System
    Replies: 2
    Last Post: 03-23-2010, 04:35 AM
  5. How to use the vector data from CL_Raw ?
    By ARme in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 12-21-2006, 08:35 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •