By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,332 Members | 1,404 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,332 IT Pros & Developers. It's quick & easy.

constrained_value type for ranged integers etc.

P: n/a
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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.