我想知道C++完整概念提议和模板约束之间的语义差异(例如,Dlang中出现的约束或C++ 1y的新概念 - 精简提议).
什么是能够比模板约束做的完整概念不能做到的?
我有以下简单的类:
class Source
{
public:
Source() = default;
Source(Source const&) = delete;
Source(Source&&) = default;
explicit Source(std::string const& fileName)
: inputStream(fileName), path_(fileName)
{}
~Source() = default;
auto path() const -> std::string
{
return this->path_;
}
std::ifstream inputStream;
private:
std::string path_;
};
auto main(int argc, char* argv[]) -> int
{
Source source(Source("test.txt"));
cout << source.path() << "\n";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
根据cppreference ifstream
有一个move
构造函数,但是当我尝试编译时MinGW 4.7.2
,我得到以下错误:
..\src\main.cpp:32:46:错误:使用已删除的函数'cy :: Source :: Source(cy :: Source &&)'在..\src\main.cpp中包含的文件中:10:0 :source.hpp:28:5:注意:'cy :: Source :: …
我对C中这种行为的动机感到好奇.是故意还是意外?
struct tpoint // tpoint is not a type name
{
int x, y;
};
typedef struct tpoint Point; // point is a type name.
Run Code Online (Sandbox Code Playgroud)
我想知道为什么Ritchie或标准委员会选择了这种行为.