Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-41425

support for Decimal128 literals

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.3.1
    • Affects Version/s: Backlog
    • Component/s: Internal Code
    • Labels:
      None
    • Fully Compatible
    • Dev Tools 2019-06-17, Dev Tools 2019-07-01

      Decimal128 are often specified Decimal128("stringliteral").
      It seems we could get some clarity and robustness out of a UDL for this type instead.
      We might be able to make it constexpr for some extra safety.

      Some sample code from a json unit test:

      ASSERT(representAs<Decimal128>(Decimal128("5"))->isEqual(Decimal128("5")));
      ASSERT(representAs<Decimal128>(Decimal128("5.5"))->isEqual(Decimal128("5.5")));
      ASSERT(representAs<Decimal128>(Decimal128("-5"))->isEqual(Decimal128("-5")));
      ASSERT(representAs<Decimal128>(Decimal128("-5.5"))->isEqual(Decimal128("-5.5")));
      
      

      I'd prefer to see this sort of thing as:

      using namespace mongo::literals;  // or whatever
      ASSERT(representAs<Decimal128>(5_d128))->isEqual(5_d128)));
      ASSERT(representAs<Decimal128>(5.5_d128))->isEqual(5.5_d128));
      ASSERT(representAs<Decimal128>(-5_d128))->isEqual(-5_d128));
      ASSERT(representAs<Decimal128>(-5.5_d128)->isEqual(-5.5_d128));
      
      

      This is quite squarely what UDLs are all about, really.

            Assignee:
            billy.donahue@mongodb.com Billy Donahue
            Reporter:
            billy.donahue@mongodb.com Billy Donahue
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: