473,320 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

constrained_value type for ranged integers etc.

I have written a constrained_value type for things like range checking
integers, non-negative doubles, etc. and I have made the source code freely
available for all at http://www.cdiggins.com/constrained_value.hpp . Below
is a small example of the type in action:

#include "constrained_value.hpp"
#include <iostream>
typedef cv::constrained_value < cv::policies::ranged_integer < 0, 59 > >
Base60_A;
typedef cv::constrained_value < cv::policies::ranged_integer < 0, 59,
cv::policies::saturating > > Base60_B;

int main()
{
Base60_A a = 10;
a = a + 20;
try {
std::cout << "exception should be thrown" << std::endl;
a = a + 40;
std::cout << "no exception thrown" << std::endl;
}
catch(...) {
std::cout << "exception caught" << std::endl;
}
Base60_B b = 10;
std::cout << "Output should be 10" << std::endl << b << std::endl;
b = b + 70;
std::cout << "Output should be 59" << std::endl << b << std::endl;
b = b - 100;
std::cout << "Output should be 0" << std::endl << b << std::endl;

std::cin.get();
return 0;
};

There is a more complete demo of the type at
http://www.cdiggins.com/cv_test.cpp .
Enjoy!

--
Christopher Diggins
http://www.heron-centric.com
Jul 22 '05 #1
0 1071

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Jason Heyes | last post by:
I would like to be able to extract an integer from a stream without having to write a test when I want the integer within some range. Unfortunately there is no range-checked integer type in the...
8
by: Jonathan Fielder | last post by:
Hi, I have a 32 bit integer value and I wish to find the single precision floating point value that is closest to but less than or equal to the integer. I also have a similar case where I need...
16
by: aruna | last post by:
Given a set of integers, how to write a program in C to sort these set of integers using C, given the following conditions a. Do not use arrays b. Do not use any comparison function like if/then...
87
by: j0mbolar | last post by:
I've read in the standard that addresses basically can't be interpreted as integers. If they can, it is implementation defined behavior. However, if they can't be viewed as integers in any sense...
2
by: Erik Frey | last post by:
Hi, I'm writing a class that parses a file format that contains unsigned 32 bit integers. I've discovered that data types like UInt32 are not CLS-compliant, and so I've been trying to figure...
2
by: Mythran | last post by:
System.Drawing.SystemColors is a class with all static properties. Here is what my short-ranged goal is... I want to enumerate all of the SystemColors properties and print the name (using...
14
by: Michael Brennan | last post by:
Hi, I wonder if there is any good reason to let different systems have different sizes of short, int and long? I think that makes it harder to plan which type to use for your program. For...
10
Cyberdyne
by: Cyberdyne | last post by:
Here is the problem, I have a form with a field named Occurence with a Short Date Value, once entered it subsequently appears in 3 fields SOL1 which adds one year, SOL2 which adds 2 years and...
9
by: foothompson | last post by:
is there a simple integer type library around that behaves like normal integers, i.e has all the same operations, but except the value can only be in a specific range, like 0 to 100, and if the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.