You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
712 B
33 lines
712 B
|
7 months ago
|
|
||
|
|
// A Scalar that asserts for uninitialized access.
|
||
|
|
template <typename T>
|
||
|
|
class SafeScalar {
|
||
|
|
public:
|
||
|
|
SafeScalar() : initialized_(false) {}
|
||
|
|
|
||
|
|
SafeScalar(const T& val) : val_(val), initialized_(true) {}
|
||
|
|
|
||
|
|
template <typename Source>
|
||
|
|
explicit SafeScalar(const Source& val) : SafeScalar(T(val)) {}
|
||
|
|
|
||
|
|
operator T() const {
|
||
|
|
VERIFY(initialized_ && "Uninitialized access.");
|
||
|
|
return val_;
|
||
|
|
}
|
||
|
|
|
||
|
|
template <typename Target>
|
||
|
|
explicit operator Target() const {
|
||
|
|
return Target(this->operator T());
|
||
|
|
}
|
||
|
|
|
||
|
|
private:
|
||
|
|
T val_;
|
||
|
|
bool initialized_;
|
||
|
|
};
|
||
|
|
|
||
|
|
namespace Eigen {
|
||
|
|
template <typename T>
|
||
|
|
struct NumTraits<SafeScalar<T>> : GenericNumTraits<T> {
|
||
|
|
enum { RequireInitialization = 1 };
|
||
|
|
};
|
||
|
|
} // namespace Eigen
|