Thread: Opinions: Is this template worthwhile as a stand-alone project?

  1. #1
    Registered User
    Join Date
    Feb 2022
    Posts
    45

    Opinions: Is this template worthwhile as a stand-alone project?

    Ranged Numeric Types in C++

    I've started writing a simple template class for automating range checking in specialized numeric types, inspired by the ranged types in languages such as Pascal and Ada. At the moment it is mainly meant for integer types, though I've made it flexible enough that it should work with floating-point types (I may need to revisit this later).

    It is just a stub at this point, but it should make it easier to define numeric types which don't fit the usual 8/16/32/64 bit signed and unsigned sizes. It allow the client-programmer to select a base type define both a lower and an upper bound, and define how it should behave on either underflow or overflow (with the choices at the moment being to wrap around; to saturate at the boundary; or to throw an exception). The usual arithmetic operators will all be supported.

    The question I have is this: is this really a useful class to write, and will others find it useful enough that it is worth providing publicly? Can you think of use cases where this would make things easier for someone working on a real-world project?

  2. #2

  3. #3
    Registered User
    Join Date
    Feb 2022
    Posts
    45
    @thmm - OK, that's useful to know, though I would say that the focus is a bit different. My goal is less about giving mathematical safety in the existing integer ranges, and more on allowing the client-programmer to select the size and ranges. Also, my code parameterizes the handling of overflows and underflows, rather than assuming that throwing an exception is always the correct response.

  4. #4
    Registered User
    Join Date
    Sep 2020
    Posts
    146
    @Schol-R-LEA-2,

    yes, it's not 100% what you look for. Maybe you can add to it or modify it. Might be easier than starting from scratch.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Opinions for a school project
    By wtd81 in forum C++ Programming
    Replies: 18
    Last Post: 01-24-2016, 02:41 AM
  2. Replies: 2
    Last Post: 02-28-2006, 02:01 PM
  3. Is C++.NET worthwhile?
    By dxfoo in forum C++ Programming
    Replies: 16
    Last Post: 09-09-2005, 03:00 AM
  4. What's the 'f' stand for?
    By Krak in forum Game Programming
    Replies: 4
    Last Post: 09-25-2003, 02:24 PM
  5. what does vbe stand for?
    By stupid_mutt in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-15-2001, 05:53 PM

Tags for this Thread