C++ g++;7.2.0自动非类型参数扣除失败
我尝试使用自动非类型参数(c++17)。 我希望'Sample1::type'应该是'integral_constraint',但它与'Sample0::type'相同 是g++错误还是我对该功能的误解? 我在Ubuntu 17.10上使用g++(Ubuntu 7.2.0-8ubuntu3)7.2.0C++ g++;7.2.0自动非类型参数扣除失败,c++,templates,c++17,auto,non-type,C++,Templates,C++17,Auto,Non Type,我尝试使用自动非类型参数(c++17)。 我希望'Sample1::type'应该是'integral_constraint',但它与'Sample0::type'相同 是g++错误还是我对该功能的误解? 我在Ubuntu 17.10上使用g++(Ubuntu 7.2.0-8ubuntu3)7.2.0 -- auto_param.cxx -- #include <iostream> #include <type_traits> #include <boost/typ
-- auto_param.cxx --
#include <iostream>
#include <type_traits>
#include <boost/type_index.hpp>
template <auto V>
struct Value {
using type = std::integral_constant<decltype(V), V>;
};
template <typename T>
auto demangle() {
return boost::typeindex::type_id_with_cvr<T>().pretty_name();
}
void zero_as_uint() {
using Sample0 = Value<0u>;
std::cout << __func__ << ": " << demangle<Sample0::type>() << std::endl;
}
void zero_as_int() {
using Sample1 = Value<0>;
std::cout << __func__ << ": " << demangle<Sample1::type>() << std::endl;
}
int main(int, char**) {
zero_as_uint();
zero_as_int();
return 0;
}
-----------------------------
$ g++ -Wall -std=c++17 auto_param.cxx && ./a.out
zero_as_uint: std::integral_constant<unsigned int, 0u>
zero_as_int: std::integral_constant<unsigned int, 0u>
--auto_param.cxx--
#包括
#包括
#包括
模板
结构值{
使用type=std::integral_常量;
};
模板
自动demangle(){
return boost::typeindex::type_id_with_cvr().pretty_name();
}
void zero_as_uint(){
使用样本0=值;
std::cout这是一个。进一步简化的示例如下所示:
#include <type_traits>
template <auto V>
struct Value {
using type = std::integral_constant<decltype(V), V>;
};
static_assert(!std::is_same_v<Value<0u>::type, Value<0>::type>);
#包括
模板,但它在最新的主干中是固定的。这是一个。进一步简化的示例如下所示:
#include <type_traits>
template <auto V>
struct Value {
using type = std::integral_constant<decltype(V), V>;
};
static_assert(!std::is_same_v<Value<0u>::type, Value<0>::type>);
#包括
模板,但它在最新的主干中已修复。模板是表示T可以是类型或非类型的新方式吗?我习惯于看到“类”或“类型名” there@Zebrafish或者,它必须是一个变量,你可能已经在那里看到了int
,对吧?好吧,这里是一样的,只是类型被推导出来了。我们在gcc 8.0之前不应该使用这个特性。谢谢!模板是一种新的说法,它可以是类型也可以是非类型吗?我习惯于看到“类”或“类型名” there@Zebrafish或者,它必须是一个变量,您可能已经在那里看到了int
,对吗?好吧,这里是一样的,只是类型被推导出来了。我们不应该在gcc 8.0之前使用此功能。谢谢!