G
g3rc4n
i know that macros shouldn't be used in c++ unnecessarily because of
scope rules, but what if i put something like this in destructor's
where i don't know if T will throw something, as macros will also make
it clear to the reader what I'm trying to achieve
if i put T in an std::auto_ptr i can't assert nothing is thrown
#define ON_SOMETHING_THROWN \
::abort();
#define START_ASSERT_NOTHING_THROWN \
try{
#define END_ASSERT_NOTHING_THROWN \
} \
catch(...){ \
ON_SOMETHING_THROWN \
}
template<typename T>
class foo{
public:
foo():
ptr(new T()){
}
~foo(){
START_ASSERT_NOTHING_THROWN
delete ptr;
END_ASSERT_NOTHING_THROWN
}
private:
T* ptr;
};
scope rules, but what if i put something like this in destructor's
where i don't know if T will throw something, as macros will also make
it clear to the reader what I'm trying to achieve
if i put T in an std::auto_ptr i can't assert nothing is thrown
#define ON_SOMETHING_THROWN \
::abort();
#define START_ASSERT_NOTHING_THROWN \
try{
#define END_ASSERT_NOTHING_THROWN \
} \
catch(...){ \
ON_SOMETHING_THROWN \
}
template<typename T>
class foo{
public:
foo():
ptr(new T()){
}
~foo(){
START_ASSERT_NOTHING_THROWN
delete ptr;
END_ASSERT_NOTHING_THROWN
}
private:
T* ptr;
};