Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please allow compile-time evaluation of DataType::id() (constexpr), platform-independently #189

Closed
N-Dekker opened this issue Aug 20, 2024 · 1 comment

Comments

@N-Dekker
Copy link

N-Dekker commented Aug 20, 2024

DataType::id() is defined "constexpr", at

constexpr DataTypeId id() const { return operations_->id; }

However, it appears that it can only be evaluated at compile-time when using MSVC, because it depends on TENSORSTORE_DATA_TYPE_CONSTEXPR_OPERATIONS, which is only defined for MSVC:

#ifdef _MSC_VER
// On MSVC, if `MakeDataTypeOperations<T>::operations` is not declared
// constexpr, it is initialized dynamically, which can happen too late if
// `DataType` is used from a global dynamic initializer, e.g. in order to
// allocate an Array.
#define TENSORSTORE_DATA_TYPE_CONSTEXPR_OPERATIONS
#endif

TENSORSTORE_DATA_TYPE_CONSTEXPR_OPERATIONS specifies whether or not MakeDataTypeOperations::operations is constexpr:

#ifdef TENSORSTORE_DATA_TYPE_CONSTEXPR_OPERATIONS
static constexpr internal::DataTypeOperations operations =
DataTypeOperationsImpl<T>;
#else
static const internal::DataTypeOperations operations;

As a consequence, a client function that calls DataType::id() may only evaluated at compile-time evaluation when using MSVC. This appears inconvenient to me.

Would it be possible to allow compile-time evaluation of DataType::id() on any of the supported platforms?

@N-Dekker N-Dekker changed the title Please allow compile-time evaluation of DataType::id() (constexpr), platform-independent Please allow compile-time evaluation of DataType::id() (constexpr), platform-independently Aug 20, 2024
@N-Dekker
Copy link
Author

N-Dekker commented Sep 6, 2024

Thank you very much, @laramiel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant