Turi Create
4.0
|
#include <core/data/flexible_type/flexible_type.hpp>
Public Member Functions | |
flexible_type () noexcept | |
template<typename T > | |
flexible_type (std::initializer_list< T > &&list) | |
~flexible_type () | |
flexible_type (const flexible_type &other) noexcept | |
flexible_type (flexible_type &other) noexcept | |
template<typename T > | |
flexible_type (const T &other, typename std::enable_if< has_direct_conversion_to_flexible_type< T >::value >::type *=nullptr) | |
flexible_type (flexible_type &&other) noexcept | |
flexible_type (const flexible_type &&other) noexcept | |
template<typename T > | |
flexible_type (T &&other, typename std::enable_if< has_direct_conversion_to_flexible_type< typename std::remove_reference< T >::type >::value >::type *=nullptr) | |
flexible_type & | soft_assign (const flexible_type &other) |
flexible_type & | operator= (const flexible_type &other) noexcept |
flexible_type & | operator= (flexible_type &other) noexcept |
flexible_type & | operator= (flexible_type &&other) noexcept |
flexible_type & | operator= (const flexible_type &&other) noexcept |
template<typename T > | |
std::enable_if< has_direct_conversion_to_flexible_type< T >::value, flexible_type & >::type | operator= (const T &other) |
flexible_type & | operator= (flex_undefined other) |
template<typename T > | |
std::enable_if< has_direct_conversion_to_flexible_type< typename std::remove_reference< T >::type >::value, flexible_type & >::type | operator= (T &&other) |
void | reset (flex_type_enum target_type) |
void | reset () |
flexible_type & | set_date_time_from_timestamp_and_offset (const std::pair< flex_int, int32_t > &datetime, const int32_t microsecond=0) |
std::pair< flex_int, int32_t > | get_date_time_as_timestamp_and_offset () const |
int32_t | get_date_time_microsecond () const |
void | swap (flexible_type &b) |
template<typename T > | |
T & | mutable_get () |
template<typename T > | |
const T & | get () const |
template<typename T > | |
T & | reinterpret_mutable_get () |
template<typename T > | |
const T & | reinterpret_get () const |
flex_type_enum | get_type () const |
std::type_index | type () const |
size_t | which () const |
size_t | hash () const |
uint128_t | hash128 () const |
bool | is_zero () const |
bool | is_na () const |
bool | contains_na () const |
template<typename Visitor > | |
auto | apply_mutating_visitor (Visitor visitor) -> decltype(visitor(prototype_flex_int)) |
template<typename Visitor > | |
auto | apply_visitor (Visitor visitor) const -> decltype(visitor(prototype_flex_int)) |
template<typename Visitor > | |
auto | apply_mutating_visitor (Visitor visitor, const flexible_type &other) -> decltype(visitor(prototype_flex_int, flex_int())) |
template<typename Visitor > | |
auto | apply_visitor (Visitor visitor, const flexible_type &other) const -> decltype(visitor(prototype_flex_int, flex_int())) |
template<class T , typename std::enable_if< std::is_integral< T >::value >::type * = (void*)NULL> | |
FLEX_ALWAYS_INLINE_FLATTEN | operator T () const |
Implicit cast to integral types. | |
template<class T , typename std::enable_if< std::is_floating_point< T >::value >::type * = (void*)NULL> | |
FLEX_ALWAYS_INLINE_FLATTEN | operator T () const |
Implicit cast to floating point types. | |
operator flex_string () const | |
operator flex_vec () const | |
operator flex_nd_vec () const | |
operator flex_list () const | |
operator flex_dict () const | |
operator flex_date_time () const | |
operator flex_image () const | |
flexible_type | operator- () const |
flexible_type & | operator+= (const flexible_type &other) |
flexible_type & | operator-= (const flexible_type &other) |
flexible_type & | operator/= (const flexible_type &other) |
flexible_type & | operator%= (const flexible_type &other) |
flexible_type & | operator*= (const flexible_type &other) |
flexible_type | operator+ (const flexible_type &other) const |
flexible_type | operator- (const flexible_type &other) const |
flexible_type | operator* (const flexible_type &other) const |
flexible_type | operator/ (const flexible_type &other) const |
flexible_type | operator% (const flexible_type &other) const |
bool | operator== (const flexible_type &other) const |
bool | operator!= (const flexible_type &other) const |
bool | approx_equal (const flexible_type &other) const |
bool | identical (const flexible_type &other) const |
bool | operator< (const flexible_type &other) const |
bool | operator> (const flexible_type &other) const |
bool | operator<= (const flexible_type &other) const |
bool | operator>= (const flexible_type &other) const |
flexible_type & | operator++ () |
Preincrement. Equivalent to (*this)+=1. | |
flexible_type | operator++ (int) |
Preincrement. Equivalent to (*this)+=1, returning a copy of the previous value. | |
flexible_type & | operator-- () |
Preincrement. Equivalent to (*this)-=1. | |
flexible_type | operator-- (int) |
Preincrement. Equivalent to (*this)-=1, returning a copy of the previous value. | |
template<typename T > | |
flexible_type | operator- (const T &other) const |
template<typename T > | |
flexible_type | operator+ (const T &other) const |
template<typename T > | |
flexible_type | operator/ (const T &other) const |
template<typename T > | |
flexible_type | operator% (const T &other) const |
template<typename T > | |
flexible_type | operator* (const T &other) const |
template<typename T > | |
bool | operator== (const T &other) const |
template<typename T > | |
bool | operator!= (const T &other) const |
template<typename T > | |
bool | operator< (const T &other) const |
template<typename T > | |
bool | operator> (const T &other) const |
template<typename T > | |
bool | operator<= (const T &other) const |
template<typename T > | |
bool | operator>= (const T &other) const |
flex_float & | operator[] (size_t index) |
const flex_float & | operator[] (size_t index) const |
flexible_type & | array_at (size_t index) |
const flexible_type & | array_at (size_t index) const |
flexible_type & | dict_at (const flexible_type &index) |
const flexible_type & | dict_at (const flexible_type &index) const |
flexible_type & | operator() (size_t index) |
const flexible_type & | operator() (size_t index) const |
flexible_type & | operator() (const flexible_type &index) |
const flexible_type & | operator() (const flexible_type &index) const |
size_t | size () const |
void | resize (size_t s) |
void | clear () |
void | erase (const flexible_type &index) |
void | push_back (flex_float i) |
void | push_back (const flexible_type &i) |
void | save (oarchive &oarc) const |
void | load (iarchive &iarc) |
template<typename Visitor > | |
FLEX_ALWAYS_INLINE_FLATTEN auto | apply_visitor (Visitor visitor) const -> decltype(visitor(prototype_flex_int)) |
template<typename Visitor > | |
FLEX_ALWAYS_INLINE_FLATTEN auto | apply_visitor (Visitor visitor, const flexible_type &other) const -> decltype(visitor(prototype_flex_int, flex_int())) |
overload | |
template<typename T > | |
std::enable_if<!std::is_integral< T >::value &&!std::is_floating_point< T >::value, T >::type | to () const |
template<typename T > | |
std::enable_if< std::is_integral< T >::value, T >::type | to () const |
template<typename T > | |
std::enable_if< std::is_floating_point< T >::value, T >::type | to () const |
The flexible_type is an automatic, self-managing union between the following types.
It is nearly every operator overloaded which allows it to behave very similarly to python data types.
The internal representation of the flexible_type is simply:
The type information for the contents of the flexible type can be obtained in three ways.
Knowing the type of the contents, the flexible_type::get() function can be used to extract a reference to the content.
If the incorrect type is provided, the flexible_type::get() function will throw a runtime exception.
A large number of casting operators are also provided and these work as expected.
However, there are certain ambiguous cases whch do cause issues when using the explicit cast so, the flexible_type::to() function is generally preferred:
A special undefined type is provided which is useful for identifying missing values (or the None value/type in Python). Such a value can be created using:
Practically every operator is overloaded, and the behaviors are relatively intuitive. See the documentation for each operator to determine legality. There are also special operator overloads to simplify access to the vector. For instance, flexible_type::operator[], flexible_type::clear() and flexible_type::push_back(). In all cases, a runtime exception is thrown if an invalid type combination is encountered.
The basic rule of the flexible_type is that the internal type is always preserved. Only an assignment can change the internal type of the object. Also, for consistency, operations between two flexible types always return a type corresponding to the flexible_type on the left of the operation. i.e.
This is true also for operations where the 2nd argument is an arbitrary type.
The only exception to the rule is when the first argument is not a flexible type and the 2nd argument is a flexible type. In which case, the return type is the a flexible type corresponding to the type on the right.
In summary: Where flexible_type_A is used to denote a flexible_type where the internal contents are of type A, and OP is an arbitrary operator,
This does mean that the binary operators are not commutative when performed across different types. ex:
Of the most powerful feature of the flexible_type, is the visitor mechanism which is designed in a very similar manner to that of the boost::variant. See flexible_type::apply_visitor(Visitor) or flexible_type::apply_mutating_visitor(Visitor) for details.
Sometimes it can be useful to be able to query (at runtime, or at compile time) whether certain flexible_type operations will succeed or not. A number of useful functions are provided.
Runtime Capability Queries:
Compile-time Capability Queries:
Performance of the flexible_type is generally extremely good. With modern compilers (sometimes with inlining limit bumped up) can sometimes produce code which is equivalent to, or runs as fast as the version using native types especially if certain type constraints are set-up before hand. For instance:
Integers and Floating point values are stored in-place inside the flexible_type. All other types are somewhat more complex (strings, vectors etc) and are optimized by copy on write. i.e.
Both b and a will reference the same "hello world" until either one of them gets mutated. As such, all inplace operations (get(), apply_visitor(Visitor)) require const, but also have a mutating version (mutating_get(), apply_mutating_visitor(Visitor)).
Definition at line 249 of file flexible_type.hpp.
|
inlinenoexcept |
Default Constructor. By default constructs an integer of value 0.
Definition at line 1650 of file flexible_type.hpp.
turi::flexible_type::flexible_type | ( | std::initializer_list< T > && | list | ) |
Construct from initializer List. Makes a vector
|
inline |
Destructor.
Definition at line 1661 of file flexible_type.hpp.
|
inlinenoexcept |
Copy constructor. Assigns this to a copy of other.
Definition at line 1669 of file flexible_type.hpp.
|
inlinenoexcept |
Copy constructor. Assigns this to a copy of other.
Definition at line 1674 of file flexible_type.hpp.
turi::flexible_type::flexible_type | ( | const T & | other, |
typename std::enable_if< has_direct_conversion_to_flexible_type< T >::value >::type * | = nullptr |
||
) |
Copy constructor. Assigns this from arbitrary type. See flexible_type::operator=
|
inlinenoexcept |
Move constructor. Just assigns myself to the other, destroying the other.
Definition at line 1685 of file flexible_type.hpp.
|
inlinenoexcept |
Move constructor. (Const overload. Required since the T&& universal reference has a tendency to capture everything)
Definition at line 1691 of file flexible_type.hpp.
turi::flexible_type::flexible_type | ( | T && | other, |
typename std::enable_if< has_direct_conversion_to_flexible_type< typename std::remove_reference< T >::type >::value >::type * | = nullptr |
||
) |
Move constructor. Assigns this from arbitrary type
auto turi::flexible_type::apply_mutating_visitor | ( | Visitor | visitor | ) | -> decltype(visitor(prototype_flex_int)) |
Executes an apply visitor on the flexible type. The apply visitor object must have a function void operator()(T& t) for every type T the flexible type can contain. The operator() function can be itself templated for convenience. For instance, the following visitor will add the value "1" to the flexible_type if the flexible_type contains an integer, and will ignore otherwise.
The visitor can return values but all versions of the operator() function must return exactly the same type. For instance:
In which case, apply_mutating_visitor will return a value:
This function assumes that the function will mutate the value. If the function does not mutate the value, the alternative apply_visitor(Visitor) should be used.
auto turi::flexible_type::apply_mutating_visitor | ( | Visitor | visitor, |
const flexible_type & | other | ||
) | -> decltype(visitor(prototype_flex_int, flex_int())) |
Executes a binary visitor on the flexible type. The binary apply visitor object must have a function void operator()(T& t, const U& u) for every pair of types T and U the flexible type can contain. The operator() function can be itself templated for convenience. For instance, the following visitor will do a += if both types are integer.
Just like the unary apply_mutating_visitor. the visitor can return a value, but all versions of operator() must return an identical type.
This function assumes that the function will mutate the value. If the function does not mutate the value, the alternative apply_visitor(Visitor, const flexible_type&) should be used.
auto turi::flexible_type::apply_visitor | ( | Visitor | visitor | ) | const -> decltype(visitor(prototype_flex_int)) |
Executes a non-mutating apply visitor on the flexible type. The apply visitor object must have a function void operator()(const T& t) for every type T the flexible type can contain. The operator() function can be itself templated for convenience. For instance, the following visitor will return one plus the value of the flexible_type if it contains an integer, or returns 0 otherwise.
This function requires that the function does not mutate the value. If the function does mutate the value, the alternative apply_mutating_visitor(Visitor) should be used.
auto turi::flexible_type::apply_visitor | ( | Visitor | visitor, |
const flexible_type & | other | ||
) | const -> decltype(visitor(prototype_flex_int, flex_int())) |
Executes a binary visitor on the flexible type. The binary apply visitor object must have a function void operator()(const T& t, const U& u) for every pair of types T and U the flexible type can contain. The operator() function can be itself templated for convenience. For instance, the following visitor will return the sum of both values if only if both types are integral.
Just like the unary apply_visitor. the visitor can return a value, but all versions of operator() must return an identical type.
This function assumes that the function will not mutate the value. If the function does mutate the value, the alternative apply_mutating_visitor(Visitor, const flexible_type&) should be used.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 1928 of file flexible_type.hpp.
|
inline |
Compares if two flexible types are equivalent in value. i.e. permitting comparisons between integer and floating point types.
Definition at line 2212 of file flexible_type.hpp.
|
inline |
List indexing operator.
Definition at line 2323 of file flexible_type.hpp.
|
inline |
List indexing operator.
Definition at line 2329 of file flexible_type.hpp.
|
inline |
Array clear function.
Definition at line 2435 of file flexible_type.hpp.
bool turi::flexible_type::contains_na | ( | ) | const |
Returns true if the value, or any contained value in a dictionary or list type, is considered a "missing value" or NA.
|
inline |
dict indexing operator.
Definition at line 2334 of file flexible_type.hpp.
|
inline |
dict indexing operator.
Definition at line 2349 of file flexible_type.hpp.
void turi::flexible_type::erase | ( | const flexible_type & | index | ) |
Dict element erase function.
const T& turi::flexible_type::get | ( | ) | const |
Gets a const reference to the value stored inside the flexible_type. T must be one of the flexible_type types. All other types will result in a compile type assertion failure. If the stored type does not match T, it will result in a run-time assertion failure.
|
inline |
Where the current flexible_type contains a datetime type, returns the datetime as a pair of posix timestamp value and its timezone offset.
The timezone offset is integral in fifteen-minute increments. i.e. a offset of 8 means timezone +2
Definition at line 1452 of file flexible_type.hpp.
|
inline |
Gets the date_time microsecond value
Definition at line 1459 of file flexible_type.hpp.
|
inline |
Returns the type of the underlying storage
Definition at line 1867 of file flexible_type.hpp.
|
inline |
Returns a 64 bit hash of the underlying value, switched on type.
Definition at line 1880 of file flexible_type.hpp.
|
inline |
Returns a 128 bit hash of the underlying value, switched on type. This hash is appropriate for unique identification.
Definition at line 1884 of file flexible_type.hpp.
|
inline |
Like operator== but requires also types to be equivalent.
Definition at line 2216 of file flexible_type.hpp.
|
inline |
Returns true if the value is considered a "missing value" or NA.
|
inline |
Returns true if the value is equal to this type's equivalent of zero.
|
inline |
Deserializer. Loads the flexible_type from an archive object. Note that the type of the flexible_type may change.
Definition at line 2489 of file flexible_type.hpp.
T& turi::flexible_type::mutable_get | ( | ) |
Gets a modifiable reference to the value stored inside the flexible_type. T must be one of the flexible_type types. All other types will result in a compile type assertion failure. If the stored type does not match T, it will result in a run-time assertion failure.
|
inline |
Implicit cast to flex_date_time
Definition at line 2121 of file flexible_type.hpp.
|
inline |
Implicit cast to vector<pair<flexible_type, flexible_type>>
Definition at line 2117 of file flexible_type.hpp.
|
inline |
Implicit cast to flex_image
Definition at line 2125 of file flexible_type.hpp.
|
inline |
Implicit cast to vector<flexible_type>
Definition at line 2113 of file flexible_type.hpp.
|
inline |
Implicit cast to ndarray<double>
Definition at line 2109 of file flexible_type.hpp.
|
inline |
Implicit cast to string
Definition at line 2101 of file flexible_type.hpp.
|
inline |
Implicit cast to vector<double>
Definition at line 2105 of file flexible_type.hpp.
|
inline |
Compares if two flexible types are not equivalent in value. i.e. permitting comparisons between integer and floating point types. Same as flexible_type::approx_equal
Definition at line 2208 of file flexible_type.hpp.
bool turi::flexible_type::operator!= | ( | const T & | other | ) | const |
Equality comparison operator with arbitrary type. Equivalent to (*this) != (flexible_type)(other);
|
inline |
Modulus operator. Equivalent to
Note that unlike regular C++ typing rules, the resultant type is always the type of the left hand side. i.e. int + float = int, and float + int = float.
Definition at line 2195 of file flexible_type.hpp.
flexible_type turi::flexible_type::operator% | ( | const T & | other | ) | const |
Modulos operator with arbitrary type. Equivalent to (*this) % (flexible_type)(other);
|
inline |
mod-equal operator.
Definition at line 2156 of file flexible_type.hpp.
|
inline |
List indexing operator.
Definition at line 2361 of file flexible_type.hpp.
|
inline |
List indexing operator.
Definition at line 2373 of file flexible_type.hpp.
|
inline |
DIct indexing operator.
Definition at line 2383 of file flexible_type.hpp.
|
inline |
Dict indexing operator.
Definition at line 2395 of file flexible_type.hpp.
|
inline |
Multiplication operator. Equivalent to
Note that unlike regular C++ typing rules, the resultant type is always the type of the left hand side. i.e. int + float = int, and float + int = float.
Definition at line 2180 of file flexible_type.hpp.
flexible_type turi::flexible_type::operator* | ( | const T & | other | ) | const |
Multiplication operator with arbitrary type. Equivalent to (*this) * (flexible_type)(other);
|
inline |
times-equal operator.
Definition at line 2161 of file flexible_type.hpp.
|
inline |
Plus operator.
Note that unlike regular C++ typing rules, the resultant type is always the type of the left hand side. i.e. int + float = int, and float + int = float.
Definition at line 2167 of file flexible_type.hpp.
flexible_type turi::flexible_type::operator+ | ( | const T & | other | ) | const |
Addition operator with arbitrary type. Equivalent to (*this) + (flexible_type)(other);
|
inline |
plus-equal operator.
Definition at line 2136 of file flexible_type.hpp.
|
inline |
negation operator.
Definition at line 2129 of file flexible_type.hpp.
|
inline |
Subtract operator. Equivalent to
Note that unlike regular C++ typing rules, the resultant type is always the type of the left hand side. i.e. int + float = int, and float + int = float.
Definition at line 2173 of file flexible_type.hpp.
flexible_type turi::flexible_type::operator- | ( | const T & | other | ) | const |
Subtract operator with arbitrary type. Equivalent to (*this) - (flexible_type)(other);
|
inline |
subtract-equal operator.
Definition at line 2142 of file flexible_type.hpp.
|
inline |
Division operator. Equivalent to
Note that unlike regular C++ typing rules, the resultant type is always the type of the left hand side. i.e. int + float = int, and float + int = float.
Definition at line 2188 of file flexible_type.hpp.
flexible_type turi::flexible_type::operator/ | ( | const T & | other | ) | const |
Division operator with arbitrary type. Equivalent to (*this) / (flexible_type)(other);
|
inline |
divide-equal operator.
Definition at line 2149 of file flexible_type.hpp.
|
inline |
Less than operator.
Definition at line 2220 of file flexible_type.hpp.
bool turi::flexible_type::operator< | ( | const T & | other | ) | const |
Less than comparison operator with arbitrary type. Equivalent to (*this) < (flexible_type)(other);
|
inline |
less than or equal than operator.
Definition at line 2228 of file flexible_type.hpp.
bool turi::flexible_type::operator<= | ( | const T & | other | ) | const |
Less than or equal comparison operator with arbitrary type. Equivalent to (*this) <= (flexible_type)(other);
|
inlinenoexcept |
Assignment operator. Copies the other to myself. See flexible_type::operator=
Definition at line 1710 of file flexible_type.hpp.
|
inlinenoexcept |
Assignment operator. Copies the other to myself. See flexible_type::operator=
Definition at line 1719 of file flexible_type.hpp.
|
inlinenoexcept |
Move assignment. Assigns myself from the other, destroying the other.
Definition at line 1738 of file flexible_type.hpp.
|
inlinenoexcept |
Move assignment. (Const overload. Required since the T&& universal reference has a tendency to capture everything).
Definition at line 1728 of file flexible_type.hpp.
std::enable_if< has_direct_conversion_to_flexible_type<T>::value, flexible_type&>::type turi::flexible_type::operator= | ( | const T & | other | ) |
Assignment from arbitrary type. Figures out what can be casted from provided argument and stores that. Specifically, it tests the following operations in this order.
|
inline |
operator= for the undefined type See flexible_type::operator=
Definition at line 1761 of file flexible_type.hpp.
std::enable_if<has_direct_conversion_to_flexible_type< typename std::remove_reference<T>::type>::value, flexible_type&>::type turi::flexible_type::operator= | ( | T && | other | ) |
Move assignment from arbitrary type. Figures out what can be casted from provided argument and stores that. Specifically, it tests the following operations in this order.
|
inline |
Compares if two flexible types are equivalent in value. i.e. permitting comparisons between integer and floating point types. Same as flexible_type::approx_equal
Definition at line 2203 of file flexible_type.hpp.
bool turi::flexible_type::operator== | ( | const T & | other | ) | const |
Equality comparison operator with arbitrary type. Equivalent to (*this) == (flexible_type)(other);
|
inline |
greater than operator.
Definition at line 2224 of file flexible_type.hpp.
bool turi::flexible_type::operator> | ( | const T & | other | ) | const |
Greater than comparison operator with arbitrary type. Equivalent to (*this) > (flexible_type)(other);
|
inline |
greater than or equal than operator.
Definition at line 2232 of file flexible_type.hpp.
bool turi::flexible_type::operator>= | ( | const T & | other | ) | const |
Greater than or equal comparison operator with arbitrary type. Equivalent to (*this) >= (flexible_type)(other);
|
inline |
Array indexing operator.
Definition at line 2293 of file flexible_type.hpp.
|
inline |
Array indexing operator.
Definition at line 2308 of file flexible_type.hpp.
|
inline |
Array insertion function.
Definition at line 2448 of file flexible_type.hpp.
|
inline |
Array / List insertion function.
Definition at line 2463 of file flexible_type.hpp.
const T& turi::flexible_type::reinterpret_get | ( | ) | const |
Gets a type unchecked modifiable reference to the value stored inside the flexible_type.
This is generally unsafe to use unless you really know what you are doing. Use get() instead.
Note that this is only defined for flex_int and flex_float type. It really does not make sense to use this anywhere else.
T& turi::flexible_type::reinterpret_mutable_get | ( | ) |
Gets a modifiable type unchecked modifiable reference to the value stored inside the flexible_type.
This is generally unsafe to use unless you really know what you are doing. Use get() instead.
Note that this is only defined for flex_int and flex_float type. It really does not make sense to use this anywhere else.
|
inline |
Deletes the contents of this class, resetting to a different type.
Note: Also ensures that that the reference count becomes 1.
Definition at line 1782 of file flexible_type.hpp.
|
inline |
Deletes the contents of this class, resetting to an integer
Definition at line 1825 of file flexible_type.hpp.
|
inline |
Array resize function
Definition at line 2421 of file flexible_type.hpp.
|
inline |
Serializer. Saves the flexible_type in an archive object.
Definition at line 2479 of file flexible_type.hpp.
|
inline |
Converts the current flexible type to a datetime type containing posix_timestamp value and timezone offset. The timezone offset is integral in fifteen-minute increments. i.e. a offset of 8 means timezone +2
Definition at line 1464 of file flexible_type.hpp.
|
inline |
Array length function.
Definition at line 2406 of file flexible_type.hpp.
|
inline |
Assign from another while preserving the type of the current flexible_type.
Definition at line 1703 of file flexible_type.hpp.
|
inline |
Swaps contents with another flexible_type
Definition at line 1833 of file flexible_type.hpp.
std::enable_if<!std::is_integral<T>::value && !std::is_floating_point<T>::value, T>::type turi::flexible_type::to | ( | ) | const |
Converts the flexible_type to a particular type. Behaves like the implicit cast operators, but explicit. In particular, this gets around the thorny issue that there is no way to cast to an flex_vec, flex_list or flex_dict even though the implicit cast operators exist. This is due to std::vector<T> having two constructors:
Resulting in two possible implicit cast routes when doing:
This function provides an explicit cast allowing the following to be written:
Of course, the alternative of is always available.
And indeed, the implementation of to() simply redirects the calls.
std::enable_if<std::is_integral<T>::value, T>::type turi::flexible_type::to | ( | ) | const |
Converts the flexible_type to a particular type. Behaves like the implicit cast operators, but explicit. In particular, this gets around the thorny issue that there is no way to cast to an flex_vec, flex_list or flex_dict even though the implicit cast operators exist. This is due to std::vector<T> having two constructors:
Resulting in two possible implicit cast routes when doing:
This function provides an explicit cast allowing the following to be written:
Of course, the alternative of is always available.
And indeed, the implementation of to() simply redirects the calls.
std::enable_if<std::is_floating_point<T>::value, T>::type turi::flexible_type::to | ( | ) | const |
Converts the flexible_type to a particular type. Behaves like the implicit cast operators, but explicit. In particular, this gets around the thorny issue that there is no way to cast to an flex_vec, flex_list or flex_dict even though the implicit cast operators exist. This is due to std::vector<T> having two constructors:
Resulting in two possible implicit cast routes when doing:
This function provides an explicit cast allowing the following to be written:
Of course, the alternative of is always available.
And indeed, the implementation of to() simply redirects the calls.
|
inline |
Returns the type index of the underlying storage. For compatibility with variant.
Definition at line 1872 of file flexible_type.hpp.
|
inline |
Returns an integer ID identifying the type of the underlying storage. Equivalent to (size_t)(get_type()). For compatibility with variant.
Definition at line 1876 of file flexible_type.hpp.