30 value_.d =
static_cast<double>(v);
34 value_.d =
static_cast<double>(v);
38 value_.i =
static_cast<int64_t
>(v);
42 value_.i =
static_cast<int64_t
>(v);
46 value_.i =
static_cast<int64_t
>(v);
50 value_.i =
static_cast<int64_t
>(v);
58 template <
typename T =
int64_t>
60 typename std::enable_if<!std::is_same<T, long>::value>::
type* = 0) {
62 value_.i =
static_cast<int64_t
>(v);
66 value_.i =
static_cast<int64_t
>(v);
70 value_.i =
static_cast<int64_t
>(v);
74 value_.i =
static_cast<int64_t
>(v);
81 value_.i =
static_cast<int64_t
>(v);
87 value_.i = -
static_cast<int64_t
>(
94 value_.b =
static_cast<bool>(v);
127 template <
typename T>
130 return static_cast<T
>(value_.d);
132 return static_cast<T
>(value_.i);
134 return static_cast<T
>(value_.b);
141 const std::string& error_msg)
const {
142 if (scalar_type_ != other.scalar_type_) {
143 if (error_msg.empty()) {
154 std::string scalar_type_str;
155 std::string value_str;
157 scalar_type_str =
"Double";
160 scalar_type_str =
"Int64";
163 scalar_type_str =
"Bool";
164 value_str = value_.b ?
"true" :
"false";
168 return scalar_type_str +
":" + value_str;
171 template <
typename T>
174 return value_.d == value;
176 return value_.i == value;
195 value_.b == other.value_.b;
std::string ToString() const
bool Equal(bool value) const
Scalar(long v, typename std::enable_if<!std::is_same< T, long >::value >::type *=0)
bool Equal(Scalar other) const
void AssertSameScalarType(Scalar other, const std::string &error_msg) const
T To() const
To<T>() does not check for scalar type and overflows.
bool Equal(T value) const
Generic file read and write utility for python interface.
std::string to_string(const T &n)