The Wayback Machine - https://web.archive.org/web/20200917214506/https://github.com/xtensor-stack/xtensor-fftw/issues/8
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

Replace template specialization workaround with `= delete` syntax #8

Open
egpbos opened this issue Oct 3, 2017 · 2 comments
Open

Replace template specialization workaround with `= delete` syntax #8

egpbos opened this issue Oct 3, 2017 · 2 comments
Labels

Comments

@egpbos
Copy link
Member

@egpbos egpbos commented Oct 3, 2017

We use template specializations to make sure we get the correct precision. The problem, for instance, with a non-template f(const xt::xarray<float> &input) is that it will also compile when you pass a xt::xarray<double>. Passing by const-reference in this sense behaves similarly to passing by value; it triggers the creation of a temporary variable -- input in this case -- though in the case of a reference the data is not actually copied.

Using = delete syntax on the default template, e.g.:

template<typename real_t>
xt::xarray< std::complex<real_t> > fft(const xt::xarray<real_t> &input) = delete;

we can make sure that calls to non-implemented specializations don't compile. If this is left out, the compilation will succeed, but the linker will fail, and this gives less informative error messages.

Unfortunately, clang has a bug that prevents us from using the nice = delete syntax. For the moment we're using a workaround:

template<typename real_t>
xt::xarray< std::complex<real_t> > fft(const xt::xarray<real_t> &input) {
   static_assert(sizeof(real_t) == 0, "Only specializations of fft can be used");
};

This is ugly. Once the bug in clang is fixed, we will want to replace this with the = delete syntax.

@egpbos egpbos added the code quality label Nov 30, 2017
@egpbos
Copy link
Member Author

@egpbos egpbos commented Jan 4, 2018

It seems like it's been solved since clang 3.9 and 5.0. Will have to decide on how to proceed: upgrade compiler dependencies or keep the code as it is.

@egpbos
Copy link
Member Author

@egpbos egpbos commented Sep 11, 2018

It seems like this is not actually used for fft and ifft anymore in basic.hpp.

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

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.