I am trying to understand how to use Ensures()
in code. As given in the example, if I tried using Ensures()
as follows...
int main(void)
{
int result = 0;
// Some calculation
Ensures(result == 255);
return 0;
}
If the result
variable is not equal to 255
, the program crashes with the following output "terminate called without an active exception"
. My question is how to use Ensures()
properly?
The GNU Scientific Library (GSL) is a numerical library for C and C++ programmers. It is free software under the GNU General Public License. The library provides a wide range of mathematical routines such as random number generators, special functions and least-squares fitting.
gsl::owner<T*> marks a pointer that has ownership of the referenced object. You should use gsl::owner<T> if you can not use resource handles such as smart pointers or containers. The key point about the owner is that you have to free the resource explicitly.
Under the leadership of Raghu Ramakrishnan as Chief Technical Officer (CTO) for Azure Data, Gray Systems Lab (GSL) designs, develops, and evaluates novel database system technologies, with a focus on transitioning the best ideas into Azure Data product lines.
gsl-lite is a single-file header-only implementation of the C++ Core Guidelines Support Library originally based on Microsoft GSL and adapted for C++98, C++03.
Are you using the Microsoft GSL implementation? Then if you check the gsl_assert.h
header file you will see that if GSL_TERMINATE_ON_CONTRACT_VIOLATION
is defined (which is default) then Ensures
will call std::terminate
which will give you the error you get.
If you want an exception to be thrown (with file and line-number information) then you need to define GSL_THROW_ON_CONTRACT_VIOLATION
before including the GSL.
As for if you're using Ensures
properly, then yes you are.
GSL_TERMINATE_ON_CONTRACT_VIOLATION
is removed, always calling terminate()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With