Giter Club home page Giter Club logo

Comments (6)

pedro-w avatar pedro-w commented on July 26, 2024

I think it's possible to fix this by casting away const, i.e. change lines 98-100 in Layer.hpp to

template <typename T>
const T& getLayerAs() const {
  return const_cast<Layer*>(this)->getLayerAs<T>();
}

but would appreciate an expert opinion on that!

from tmxlite.

fallahn avatar fallahn commented on July 26, 2024

Interesting 🤔 When I get a chance I'll have to try it on other platforms to see if I get the same results. However I'm not a fan of the const_cast - I think the more correct way to fix it would be to create const overloads for each of the specialisations? If I happen to find an expert I'll ask them 😅

from tmxlite.

pedro-w avatar pedro-w commented on July 26, 2024

Certainly would be do-able to create const overloads for each of the specialisations, if a little tedious. How about if it were swapped around - the specialisations are all for the const version? Then the non-const overload would cast to const (should always be safe), cast to the subclass, and then cast back to non-const (should also be safe because we know, within that same function, the pointer was to a non-const object in the first place)

from tmxlite.

fallahn avatar fallahn commented on July 26, 2024

To be honest I'd prefer to do the work (it only has to be done once to be included in the library anyway) if it means the intended behaviour is explicit. After all it was my assumption based on implicit behaviour that all compilers would pick the correct specialisation which caused the bug in the first place 😉 I've made the changes and pushed them to the const_correctness branch - give it a try and see if it fixes it for you. If it does let me know and I'll merge it. Thanks!

from tmxlite.

pedro-w avatar pedro-w commented on July 26, 2024

That certainly solved the problem I was having, 👍

from tmxlite.

fallahn avatar fallahn commented on July 26, 2024

Good enough, thanks!

from tmxlite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.