llohse / libnpy

C++ library for reading and writing of numpy's .npy files
MIT License
373 stars 71 forks source link

Does libnpy/1.0.1 support C++11? #35

Closed toge closed 1 month ago

toge commented 1 year ago

Hi. I am writing a recipe for libnpy for a package manager called conan.

Let me ask a question that has arisen while writing the recipe.

Version 1.0.1 appears to be buildable in C++11. Does libnpy officially support C++14 and not C++11?

llohse commented 1 year ago

I have not tested the compatibility with C++11 but I have not consciously used any features that would require C++14, either. If you don't get any compiler warnings, it should be fine.

ahadji05 commented 9 months ago

This code snippet: constexpr dtype_t has_typestring<float>::dtype; and the equivalent code for all other types, double, long double, int, etc. is problematic with C++11, because in C++11constexpr does not imply inline for non-static variables! That violates the One Definition Rule (ODR), so, multiple definitions fail to link.

I've done some more research on that, as I understand, there is a difference on the effect of constexpr on variables or functions between C++17 and C++11.

For functions, in C++17 & C++11, constexpr implies inline so there is no violation of the ODR. However, for non-static variables in C++11 constexpr does not imply inline!

llohse commented 1 month ago

This code snippet: constexpr dtype_t has_typestring<float>::dtype; and the equivalent code for all other types, double, long double, int, etc. is problematic with C++11, because in C++11constexpr does not imply inline for non-static variables! That violates the One Definition Rule (ODR), so, multiple definitions fail to link.

This construct is not being used anymore recent versions of libnpy.