- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The following code will not compile with icpc 15.0.2:
#include <algorithm> #include <array> #include <numeric> template<typename T> T const & (*maxer) (T const &, T const &) = std::max<T>; int main(void) { std::array<float, 8> data; std::iota(data.begin(), data.end(), 0.0f); if (std::accumulate(data.begin(), data.end(), 0.0f, maxer<float>) == 7.0f) { return 0; } else { return 1; } }
Here is the output:
$ icpc -std=c++14 -Wall -Wextra max.cc max.cc(6): error: "maxer" is not a function or static data member T const & (*maxer) (T const &, T const &) = std::max<T>; ^ max.cc(11): error: identifier "maxer" is undefined if (std::accumulate(data.begin(), data.end(), 0.0f, maxer<float>) == 7.0f) { ^ max.cc(11): error: type name is not allowed if (std::accumulate(data.begin(), data.end(), 0.0f, maxer<float>) == 7.0f) { ^ max.cc(11): error: expected an expression if (std::accumulate(data.begin(), data.end(), 0.0f, maxer<float>) == 7.0f) { ^ compilation aborted for max.cc (code 2)
This code compiles successfully under clang++ and g++. As far as I can tell it is completely standards complaint. I suspect this is just a bug. I can work around it in the meantime by removing the template and hard-coding a type.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Levi,
Yes, this is indeed a bug and thanks for catching this issue. I've filed with the developers and will update you as soon as the release with the fix is out. Appreciate your patience till then
_Kittur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for the prompt reply! In this particular case the work-around is trivial but inconvenient since you have to forward declare every type you intend to use. Looking forward to the fix.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are trying to use the new c++14 feature variable templates which according to this table in not yet support in the Intel 15.0 (or 16.0) compiler:
https://software.intel.com/en-us/articles/c14-features-supported-by-intel-c-compiler
GNU just added support for this in their latest release. Glad to hear you have a workaround.
Judy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Levi,
Thanks to Judy I just realized the support for variable template isn't there in the present version or in the upcoming 16.0 as well :(
I'll keep you updated as soon as the release with the support for this feature is out.
_Kittur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes the 5.X (I tried 5.2) release (GNU) has this support (added recently) as Judy mentioned earlier.
_Kittur

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page