[英]sample void_t example does not compile with intel compiler 19.0.4
I'm trying to compile the cppreference example code of void_t with intel compiler :我正在尝试使用英特尔编译器编译 void_t 的 cppreference 示例代码:
#include <iostream>
#include <type_traits>
#include <vector>
#include <map>
class A {};
template <typename T, typename = void>
struct is_iterable : std::false_type {};
template <typename T>
struct is_iterable<T, std::void_t<decltype(std::declval<T>().begin()),
decltype(std::declval<T>().end())>>
: std::true_type {};
// An iterator trait which value_type is always the value_type of the
// iterated container, even with back_insert_iterator which value_type is void
template <typename T, typename = void>
struct iterator_trait
: std::iterator_traits<T> {};
template <typename T>
struct iterator_trait<T, std::void_t<typename T::container_type>>
: std::iterator_traits<typename T::container_type::iterator> {};
int main()
{
std::cout << std::boolalpha;
std::cout << is_iterable<std::vector<double>>::value << '\n';
std::cout << is_iterable<std::map<int, double>>::value << '\n';
std::cout << is_iterable<double>::value << '\n';
std::cout << is_iterable<A>::value << '\n';
std::vector<int> v;
std::cout << std::is_same<iterator_trait<decltype(std::back_inserter(v))>::value_type
, iterator_trait<decltype(v.cbegin())>::value_type >::value << '\n';
}
I have the following error :我有以下错误:
main.cpp(11): error: namespace "std" has no member "void_t"
struct is_iterable<T, std::void_t<decltype(std::declval<T>().begin()),
^
main.cpp(11): error: expected a ">"
struct is_iterable<T, std::void_t<decltype(std::declval<T>().begin()),
^
main.cpp(12): error: expected a ";"
decltype(std::declval<T>().end())>>
^
main.cpp(22): error: namespace "std" has no member "void_t"
struct iterator_trait<T, std::void_t<typename T::container_type>>
^
main.cpp(22): error: expected a ">"
struct iterator_trait<T, std::void_t<typename T::container_type>>
^
main.cpp(22): error: expected a ";"
struct iterator_trait<T, std::void_t<typename T::container_type>>
^
compilation aborted for main.cpp (code 2)
I use the following line for compilation :我使用以下行进行编译:
icpc -std=c++17 main.cpp
and my icpc version is :我的icpc版本是:
icpc --version
icpc (ICC) 19.0.4.243 20190416
Copyright (C) 1985-2019 Intel Corporation. All rights reserved.
Is that mean that the 2019 version of icpc does not compile void_t ?这是否意味着 2019 版的 icpc 不编译 void_t ? That seems strange because it works on godbolt : https://godbolt.org/z/xoT8vr这看起来很奇怪,因为它适用于 Godbolt: https ://godbolt.org/z/xoT8vr
The problem is not related to a compiler but to the implementation of the C++ Standard Library it works with.问题与编译器无关,而与它所使用的 C++ 标准库的实现有关。 For instance, on Linux systems, Intel icpc
typically uses system-installed libstdc++.例如,在 Linux 系统上,英特尔icpc
通常使用系统安装的 libstdc++。 Note that the support for std::void_t
was added into libstdc++ in version 6.1 .请注意, 对std::void_t
的支持已添加到版本 6.1 中的 libstdc++ 中。
While icpc
on Godbold uses libstdc++ version 8 , your system likely have some older version installed without the support for std::void_t
.虽然Godbold 上的icpc
使用 libstdc++ 版本 8 ,但您的系统可能安装了一些不支持std::void_t
旧版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.