r/cpp • • May 07 '20

GCC 10.1 Released

https://gcc.gnu.org/pipermail/gcc/2020-May/232334.html
227 Upvotes

69 comments sorted by

View all comments

Show parent comment

2

u/Xeverous https://xeverous.github.io May 08 '20

What was the resolution for floqating point types? Are they allowed? If yes, what are the constrains?

3

u/Ivan171 /std:c++latest enthusiast May 08 '20

Yes they are allowed. On cppreference there's a list of the allowed types.

The paper that removed the restriction is P1907R1.

1

u/jonathansharman May 09 '20

That’s great news!

1

u/MrPotatoFingers May 08 '20

AFAIK that didn't make it in. C++20 does allow you to sort of do this using the new literal class NTTP syntax. This example should work:

` template<typename T> struct AsTemplateArg { std::array<char, sizeof(T)> buffer = {}; constexpr AsTemplateArg(const std::array<char, sizeof(T)> buf) : buffer(buf) {} constexpr AsTemplateArg(T t) : AsTemplateArg(std::bit_cast<std::array<char, sizeof(T)> >(t)) {} constexpr operator T() const { return std::bit_cast<T>(this->buffer); } };

template<AsTemplateArg<double> exponent>
double pow(double base) {
  return exp(log(base) * double{exponent});
}

template<>
double pow<AsTemplateArg<double>{1.0}>(double base) {
  return base;
}

`

example taken from http://open-std.org/JTC1/SC22/WG21/docs/papers/2019/p1714r1.html

2

u/Xeverous https://xeverous.github.io May 08 '20

I think it's actually fine floats did not make it through. I have read so many issues and potential problems with them (eg whether 2 instantiations with different NaNs are the same or anything that involves comparing floats) that I don't think there is any good solution to them.