草庐IT

c++ - C++17 中的 "If constexpr"在非模板函数中不起作用

我尝试使用C++17标准。我尝试使用C++17ifconstexpr的特性之一。我有一个问题......请看下面的代码。这编译没有错误。在下面的代码中,我尝试使用ifconstexpr来检查它是否是一个指针。#include#includetemplatevoidprint(Tvalue){ifconstexpr(std::is_pointer_v)std::cout但是当我重写上面的代码时,如下图,其中ifconstexpr在main函数中:#include#includeintmain(){autovalue=100;ifconstexpr(std::is_pointer_v)st

c++ - Clang 和 GCC 在强制转换 C++17 中的非类型模板参数的自动说明符中存在分歧

我基本上有一个依赖于非类型模板参数的类。我定义了一个转换,因此非类型模板参数N的对象可以转换为另一个M。我有一个可以重现这种情况的最小示例:templateclassTest{public:typedefdecltype(Integral)value_type;staticconstexprvalue_typeN=Integral;constexprTest(constvalue_type&x=0);templateconstexprexplicitoperatorTest()const;private:value_typen;};templateconstexprTest::Test

c++ - Clang 和 GCC 在强制转换 C++17 中的非类型模板参数的自动说明符中存在分歧

我基本上有一个依赖于非类型模板参数的类。我定义了一个转换,因此非类型模板参数N的对象可以转换为另一个M。我有一个可以重现这种情况的最小示例:templateclassTest{public:typedefdecltype(Integral)value_type;staticconstexprvalue_typeN=Integral;constexprTest(constvalue_type&x=0);templateconstexprexplicitoperatorTest()const;private:value_typen;};templateconstexprTest::Test

c++ - C++17 中的显式默认构造函数

在C++17中,标准库中的空标记类型现在具有标记为explicit的默认构造函数,并且也是=default。例如,std::piecewise_construct_t现在定义为structpiecewise_construct_t{explicitpiecewise_construct_t()=default;};我的问题很简单,从C++14发生这种变化的原因是什么?显式默认的显式默认构造函数(!)对空类意味着什么?(为了避免被标记为骗子:thisquestion从2010年开始询问显式默认构造函数的目的,但那是C++11之前的版本,而且是很久以前的事了,所以事情可能已经发生了变化。T

c++ - C++17 中的显式默认构造函数

在C++17中,标准库中的空标记类型现在具有标记为explicit的默认构造函数,并且也是=default。例如,std::piecewise_construct_t现在定义为structpiecewise_construct_t{explicitpiecewise_construct_t()=default;};我的问题很简单,从C++14发生这种变化的原因是什么?显式默认的显式默认构造函数(!)对空类意味着什么?(为了避免被标记为骗子:thisquestion从2010年开始询问显式默认构造函数的目的,但那是C++11之前的版本,而且是很久以前的事了,所以事情可能已经发生了变化。T

c++ - C++17 std::filesystem::path 中的 native 路径分隔符错误?

从#include升级时遇到问题至#include.似乎std::filesystem::path::wstring方法返回的字符串与experimental::filesystem中的字符串不同.我编写了以下包含输出结果的小测试程序。#include#include#includenamespacefs=std::filesystem;namespaceex=std::experimental::filesystem;usingnamespacestd;intmain(){fs::pathp1{L"C:\\temp/foo"};wcout根据https://en.cppreferen

c++ - C++17 std::filesystem::path 中的 native 路径分隔符错误?

从#include升级时遇到问题至#include.似乎std::filesystem::path::wstring方法返回的字符串与experimental::filesystem中的字符串不同.我编写了以下包含输出结果的小测试程序。#include#include#includenamespacefs=std::filesystem;namespaceex=std::experimental::filesystem;usingnamespacestd;intmain(){fs::pathp1{L"C:\\temp/foo"};wcout根据https://en.cppreferen

c++ - C++17 中已弃用的 std::is_literal_type

根据cppreference,性状std::is_literal_type在C++17中已弃用。问题是为什么和首选替代品是什么以供将来检查类型是否为literaltype. 最佳答案 AsstatedinP0174:Theis_literaltypetraitoffersnegligiblevaluetogenericcode,aswhatisreallyneededistheabilitytoknowthataspecificconstructionwouldproduceconstantinitialization.Thecor

c++ - C++17 中已弃用的 std::is_literal_type

根据cppreference,性状std::is_literal_type在C++17中已弃用。问题是为什么和首选替代品是什么以供将来检查类型是否为literaltype. 最佳答案 AsstatedinP0174:Theis_literaltypetraitoffersnegligiblevaluetogenericcode,aswhatisreallyneededistheabilitytoknowthataspecificconstructionwouldproduceconstantinitialization.Thecor

c++ - 为 C++17 提议的 UTF-8 字 rune 字有什么意义?

N4267提出的这些究竟有什么意义??它们的唯一功能似乎是防止指定扩展的ASCII字符或部分UTF-8代码点。它们仍然存储在固定宽度的8位字符中(据我了解,对于几乎所有用例来说,这是处理UTF-8的正确和最佳方式),因此它们不支持非ASCII字符全部。怎么回事?(实际上我也不完全确定我是否理解对UTF-8字符串文字的需求。我猜这是编译器担心使用Unicode字符串加上对Unicode的验证做奇怪/模棱两可的事情?) 最佳答案 EvolutionWorkingGroupissue119:N4197Addingu8characterli