checked_cast improvements

XMLWordPrintableJSON

    • Server Programmability
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      • Unconditionally return the result of a static_cast, not dynamic_cast.

      Only do the dynamic_cast in debug builds as a look-see. We don't want interferences from dynamic_cast's capability to do side-casts, producing code that only compiles in debug builds.

      • Add a sfinae check on checked_cast so it only participates in overload resolution when a static_cast would succeed.

      References:

      Realm's checked_cast import:
      https://github.com/realm/realm-core/pull/4331/files#diff-e5bfb8e3654dd2c72e622d276e0cde39f22951a14d18c28631676808c51bc8ce

      Possible improvement on that from using stdx::is_detected.
      https://gcc.godbolt.org/z/dj57bT

      Suggested by Mathias in a server-servicearch Slack thread.
      https://mongodb.slack.com/archives/CMLKU7Y1M/p1611141797007100

              Assignee:
              Unassigned
              Reporter:
              Billy Donahue
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated: